add "check Validate" support

This commit is contained in:
Tnze
2019-08-09 00:36:00 +08:00
parent bf46650ffc
commit 8d9d2a7695
6 changed files with 159 additions and 79 deletions

21
yggdrasil/validate.go Normal file
View File

@ -0,0 +1,21 @@
package yggdrasil
import "fmt"
// Validate checks if an accessToken is usable for authentication with a Minecraft server.
func (a *Access) Validate() (bool, error) {
pl := struct {
AccessToken string `json:"accessToken"`
ClientToken string `json:"clientToken"`
}{
AccessToken: a.ar.AccessToken,
ClientToken: a.ar.ClientToken,
}
resp, err := rowPost("/validate", pl)
if err != nil {
return false, fmt.Errorf("request fail: %v", err)
}
return resp.StatusCode == 204, resp.Body.Close()
}