Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose refresh token (used by GitHub Apps) #9

Merged
merged 1 commit into from Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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