Skip to content

Commit 2472d71

Browse files
authored
Add NewOAuthWithRefreshToken (ktrysmt#218)
1 parent c2eb0db commit 2472d71

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

client.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,28 @@ func NewOAuthWithCode(i, s, c string) (*Client, string) {
139139
return injectClient(a), tok.AccessToken
140140
}
141141

142+
// NewOAuthWithRefreshToken obtains a new access token with a given refresh token
143+
// and returns a *Client
144+
func NewOAuthWithRefreshToken(i, s, rt string) (*Client, string) {
145+
a := &auth{appID: i, secret: s}
146+
ctx := context.Background()
147+
conf := &oauth2.Config{
148+
ClientID: i,
149+
ClientSecret: s,
150+
Endpoint: bitbucket.Endpoint,
151+
}
152+
153+
tokenSource := conf.TokenSource(ctx, &oauth2.Token{
154+
RefreshToken: rt,
155+
})
156+
tok, err := tokenSource.Token()
157+
if err != nil {
158+
log.Fatal(err)
159+
}
160+
a.token = *tok
161+
return injectClient(a), tok.AccessToken
162+
}
163+
142164
func NewOAuthbearerToken(t string) *Client {
143165
a := &auth{bearerToken: t}
144166
return injectClient(a)

0 commit comments

Comments
 (0)