-
Notifications
You must be signed in to change notification settings - Fork 299
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
add RefreshToken method for Authenticator #233
Conversation
@strideynet |
I would love to see this merged. I get a lot of problems with my tokens not refreshing |
@Padi142 If you need the refresh token functionality right now, you can import my forked repo in which I merged this PR. |
@@ -171,6 +171,13 @@ func (a Authenticator) Token(ctx context.Context, state string, r *http.Request, | |||
return a.config.Exchange(ctx, code, opts...) | |||
} | |||
|
|||
// Return a new token if an access token has expired. | |||
// If it has not expired, return the existing token. | |||
func (a Authenticator) RefreshToken(ctx context.Context, token *oauth2.Token) (*oauth2.Token, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure calling this RefreshToken
aligns with the GoDoc comment. Perhaps GetToken
would be a clearer name - since the refreshing only occurs in certain circumstances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@strideynet
Thank you for you opinion, and I understand what you are saying.
One concern I have with naming it GetToken
is that new users of this library may mistakenly think that they can get *oauth2.Token just by calling the GetToken
function. (In fact, users need to call Authenticator Token
method to get the token for the first time.)
What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you are saying - and agree. Let's move forwards with this.
@@ -171,6 +171,13 @@ func (a Authenticator) Token(ctx context.Context, state string, r *http.Request, | |||
return a.config.Exchange(ctx, code, opts...) | |||
} | |||
|
|||
// Return a new token if an access token has expired. | |||
// If it has not expired, return the existing token. | |||
func (a Authenticator) RefreshToken(ctx context.Context, token *oauth2.Token) (*oauth2.Token, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you are saying - and agree. Let's move forwards with this.
<3 <3 |
Overview
Existing code did not have a mechanism to update access tokens with refresh tokens.
So I added
RefreshToken
method which returns a new access token if it has expired.Example of use
Related