forked from Tnze/go-mc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate.go
36 lines (28 loc) · 782 Bytes
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package yggdrasil
import (
"fmt"
"io"
)
// Validate checks if an accessToken is usable for authentication with a Minecraft server.
func (a *Access) Validate() (bool, error) {
pl := a.ar.Tokens
resp, err := rawPost("/validate", pl)
if err != nil {
return false, fmt.Errorf("request fail: %v", err)
}
return resp.StatusCode == 204, resp.Body.Close()
}
// Invalidate invalidates accessTokens using a client/access token pair.
func (a *Access) Invalidate() error {
pl := a.ar.Tokens
resp, err := rawPost("/invalidate", pl)
if err != nil {
return fmt.Errorf("request fail: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != 204 {
content, _ := io.ReadAll(resp.Body)
return fmt.Errorf("invalidate error: %v: %s", resp.Status, content)
}
return nil
}