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

39
yggdrasil/refresh.go Normal file
View File

@ -0,0 +1,39 @@
package yggdrasil
import "fmt"
type refreshPayload struct {
tokens
SelectedProfile *Profile `json:"selectedProfile,omitempty"`
RequestUser bool `json:"requestUser"`
}
// Refresh refreshes a valid accessToken.
//
// It can be used to keep a user logged in between
// gaming sessions and is preferred over storing
// the user's password in a file
func (a *Access) Refresh(profile *Profile) error {
pl := refreshPayload{
tokens: a.ar.tokens,
SelectedProfile: profile, //used to change profile, don't use now
RequestUser: true,
}
resp := struct {
*authResp
*Error
}{authResp: &a.ar}
err := post("/refresh", pl, &resp)
if err != nil {
return fmt.Errorf("post fail: %v", err)
}
if resp.Error != nil {
return resp.Error
}
return nil
}