complete yggdrasil package

This commit is contained in:
Tnze
2019-08-09 17:42:18 +08:00
parent cd852a59b5
commit 3aa48ab1be
8 changed files with 226 additions and 53 deletions

View File

@ -1,16 +1,13 @@
package yggdrasil
import "fmt"
import (
"fmt"
"io/ioutil"
)
// 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,
}
pl := a.ar.tokens
resp, err := rowPost("/validate", pl)
if err != nil {
@ -19,3 +16,21 @@ func (a *Access) Validate() (bool, error) {
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 := rowPost("/invalidate", pl)
if err != nil {
return fmt.Errorf("request fail: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != 204 {
content, _ := ioutil.ReadAll(resp.Body)
return fmt.Errorf("invalidate error: %v: %s", resp.Status, content)
}
return nil
}