complete yggdrasil package
This commit is contained in:
39
yggdrasil/refresh.go
Normal file
39
yggdrasil/refresh.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user