Skip to content

Commit 63e88b3

Browse files
authored
Merge pull request #9 from swinton/expose-refresh-token
Expose refresh token (used by GitHub Apps)
2 parents 6b1e71c + 1690dd9 commit 63e88b3

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

api/access_token.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package api
44
type AccessToken struct {
55
// The token value, typically a 40-character random string.
66
Token string
7+
// The refresh token value, associated with the access token.
8+
RefreshToken string
79
// The token type, e.g. "bearer".
810
Type string
911
// Space-separated list of OAuth scopes that this token grants.
@@ -14,9 +16,10 @@ type AccessToken struct {
1416
func (f FormResponse) AccessToken() (*AccessToken, error) {
1517
if accessToken := f.Get("access_token"); accessToken != "" {
1618
return &AccessToken{
17-
Token: accessToken,
18-
Type: f.Get("token_type"),
19-
Scope: f.Get("scope"),
19+
Token: accessToken,
20+
RefreshToken: f.Get("refresh_token"),
21+
Type: f.Get("token_type"),
22+
Scope: f.Get("scope"),
2023
}, nil
2124
}
2225

api/access_token_test.go

+22-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,28 @@ func TestFormResponse_AccessToken(t *testing.T) {
2323
},
2424
},
2525
want: &AccessToken{
26-
Token: "ATOKEN",
27-
Type: "bearer",
28-
Scope: "repo gist",
26+
Token: "ATOKEN",
27+
RefreshToken: "",
28+
Type: "bearer",
29+
Scope: "repo gist",
30+
},
31+
wantErr: nil,
32+
},
33+
{
34+
name: "with refresh token",
35+
response: FormResponse{
36+
values: url.Values{
37+
"access_token": []string{"ATOKEN"},
38+
"refresh_token": []string{"AREFRESHTOKEN"},
39+
"token_type": []string{"bearer"},
40+
"scope": []string{"repo gist"},
41+
},
42+
},
43+
want: &AccessToken{
44+
Token: "ATOKEN",
45+
RefreshToken: "AREFRESHTOKEN",
46+
Type: "bearer",
47+
Scope: "repo gist",
2948
},
3049
wantErr: nil,
3150
},

0 commit comments

Comments
 (0)