diff --git a/api/access_token.go b/api/access_token.go index 1d9631a..718d69d 100644 --- a/api/access_token.go +++ b/api/access_token.go @@ -4,6 +4,8 @@ package api type AccessToken struct { // The token value, typically a 40-character random string. Token string + // The refresh token value, associated with the access token. + RefreshToken string // The token type, e.g. "bearer". Type string // Space-separated list of OAuth scopes that this token grants. @@ -14,9 +16,10 @@ type AccessToken struct { func (f FormResponse) AccessToken() (*AccessToken, error) { if accessToken := f.Get("access_token"); accessToken != "" { return &AccessToken{ - Token: accessToken, - Type: f.Get("token_type"), - Scope: f.Get("scope"), + Token: accessToken, + RefreshToken: f.Get("refresh_token"), + Type: f.Get("token_type"), + Scope: f.Get("scope"), }, nil } diff --git a/api/access_token_test.go b/api/access_token_test.go index f2d9736..fda4f6e 100644 --- a/api/access_token_test.go +++ b/api/access_token_test.go @@ -23,9 +23,28 @@ func TestFormResponse_AccessToken(t *testing.T) { }, }, want: &AccessToken{ - Token: "ATOKEN", - Type: "bearer", - Scope: "repo gist", + Token: "ATOKEN", + RefreshToken: "", + Type: "bearer", + Scope: "repo gist", + }, + wantErr: nil, + }, + { + name: "with refresh token", + response: FormResponse{ + values: url.Values{ + "access_token": []string{"ATOKEN"}, + "refresh_token": []string{"AREFRESHTOKEN"}, + "token_type": []string{"bearer"}, + "scope": []string{"repo gist"}, + }, + }, + want: &AccessToken{ + Token: "ATOKEN", + RefreshToken: "AREFRESHTOKEN", + Type: "bearer", + Scope: "repo gist", }, wantErr: nil, },