Skip to content

Commit

Permalink
Merge pull request #9 from swinton/expose-refresh-token
Browse files Browse the repository at this point in the history
Expose refresh token (used by GitHub Apps)
  • Loading branch information
mislav committed Oct 15, 2021
2 parents 6b1e71c + 1690dd9 commit 63e88b3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
9 changes: 6 additions & 3 deletions api/access_token.go
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down
25 changes: 22 additions & 3 deletions api/access_token_test.go
Expand Up @@ -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,
},
Expand Down

0 comments on commit 63e88b3

Please sign in to comment.