complete yggdrasil package
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user