-
Notifications
You must be signed in to change notification settings - Fork 285
Do not remove refresh_token on server errors #281
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
base: develop
Are you sure you want to change the base?
Changes from 2 commits
5609e3a
6713930
abb6229
b231246
9109c6c
5cc44a2
d664205
7fe2e96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -352,7 +352,7 @@ open class OAuth2: OAuth2Base { | |
/** | ||
If there is a refresh token, use it to receive a fresh access token. | ||
|
||
If the request returns an error, the refresh token is thrown away. | ||
If the request returns an client error, the refresh token is thrown away. | ||
|
||
- parameter params: Optional key/value pairs to pass during token refresh | ||
- parameter callback: The callback to call after the refresh token exchange has finished | ||
|
@@ -366,9 +366,14 @@ open class OAuth2: OAuth2Base { | |
do { | ||
let data = try response.responseData() | ||
let json = try self.parseRefreshTokenResponseData(data) | ||
if response.response.statusCode >= 400 { | ||
switch response.response.statusCode { | ||
case 400..<500: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check still seems too strong. How about 408? They may happen just because of bad connectivity. I would rather never delete the refresh token here and let the callback deal with it. For this we would need a more detailed error with at least the response status code. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a good point. Yes, it would probably be good to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with never deleting the token and leaving that to the specific implementation. What I suggest is adding the check for the server error since it is already implemented for 500s and adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be on the safe side, @p2 could you confirm that this is ok not deleting the token here? I am just worried if nil refresh tokens are not used to check some state somewhere else in the library. |
||
self.clientConfig.refreshToken = nil | ||
throw OAuth2Error.generic("Failed with status \(response.response.statusCode)") | ||
case 500...599: | ||
throw OAuth2Error.generic("Failed with status \(response.response.statusCode)") | ||
default: | ||
break | ||
} | ||
self.logger?.debug("OAuth2", msg: "Did use refresh token for access token [\(nil != self.clientConfig.accessToken)]") | ||
callback(json, nil) | ||
|
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.
Thanks for also updating the comment – can you change to "a client error"? :)