mirror of
https://github.com/OAuthSwift/OAuthSwift.git
synced 2026-04-26 12:45:52 +03:00
[GH-ISSUE #217] Refresh OAuth2 access tokens by default in the OAuthSwiftClient #122
Labels
No labels
bug
cocoapod
duplicate
enhancement
feature-request
help wanted
help wanted
invalid
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/OAuthSwift#122
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @FGoessler on GitHub (Apr 4, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/217
@fabiomassimo created a convenience method on
OAuth2Swiftto automatically refresh the access token in case of a failure for a normal request in #209 which is nice 👍.I expected this to be the default behaviour of every request made via the
OAuthSwiftClient, which seems not to be the case right now.My suggestion:
OAuthSwiftClientand only execute it for OAuth2 requests.OAuthSwiftCredentialof the client.OAuth2SwiftI would either move them as well, move them to an extension ofOAuthSwiftClientin theOAuth2Swiftfile or transform them to class methods. What is the preferred solution?OAuth2Swiftas deprecated and let it just call through to the client. Or even remove the convenience method since no release was made since the introduction of the method and therefore no consumer of this library should be affected.Any thoughts, comments, considerations, suggestions, ...?
I would start working on a PR then. 😉
@antwerpenR commented on GitHub (May 3, 2016):
I am trying to get this to work with Meetup.com and it seems that the access token is correctly set in line 83 of authorizeWithCallbackURL but you are not storing the "expires_in" responseParameter. Also, I can find no trace of any possible use of "grant type=refresh-token" and requestOAuthAccessTokenWithParameters on line 160 is never being called. For reference, the Meetup Spec is here: http://www.meetup.com/meetup_api/auth/#oauth2server-auth-success
Am I doing something wrong or is this a bug? It does seem that the token is correct and signing of requests works properly....just no handling of the refresh
@antwerpenR commented on GitHub (May 3, 2016):
I think the solution may just be to store the "expires_in" at the same time that you store the token. Inserting these lines: 85, 86 and 87.
if let expiresIn:String = responseParameters["expires_in"], offset = Double(expiresIn) {
self.client.credential.oauth_token_expires_at = NSDate(timeInterval: offset, sinceDate: NSDate())
}
@FGoessler commented on GitHub (May 4, 2016):
I assume you're using the current version on master, right?
The expires in value is actually stored in the
requestOAuthAccessTokenWithParametersmethod.To have this automatic refresh token renewal you need to use the special method
startAuthorizedRequest(...)on the OAuth2Swift object for every request which should check for token renewal. It's currently not handled "transparently" for all request (e.g. if you do them via the GET(...) convenience methods on the OAuthSwiftClient) - this is what this issue and my PR aim for, but the work there is not finished yet and I wouldn't rely on it yet.@antwerpenR commented on GitHub (May 4, 2016):
Yes - I am on Master latest version.
I use oauthswift.authorizeWithCallbackURL(
(successfully) to get an access token which works....but I see that
"expires in" is not stored.
I then use
oauthswift.startAuthorizedRequest(requiredURL, method: .GET, parameters:...
to (successfully) sign requests and fetch data...and this works for one
hour until the token expires. At that time I get a return saying "invalid
credentials". If I do modify the code to store "expires in" then I get
and error return "expired token" when it expires.....what should I do then
to do a refresh without needing authorisation again?
Thanks for your help...!
Roger Price
On Wed, May 4, 2016 at 7:54 PM, Florian Gößler notifications@github.com
wrote:
@antwerpenR commented on GitHub (May 5, 2016):
Problem solved.
I had copied the code from the Documentation page which uses "responseType
= "token" in the initialisation of the oauthswift object.
I went back and modified your demo application to add Meetup.com and it
worked perfectly. Then I noticed that you need to use "responseType =
"code" to get your initial token properly. This causes the flow to work
properly and the refresh token and expiry times come back and do get stored
properly.
Hope I did not cause too much trouble and this clarification may help
others.
Roger Price
@Timac commented on GitHub (May 12, 2020):
The PR #596 proposes a solution:
@phatblat commented on GitHub (May 18, 2021):
Added in #596