forked from Tnze/go-mc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh.go
39 lines (31 loc) · 777 Bytes
/
refresh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
}