mirror of
https://github.com/OAuthSwift/OAuthSwift.git
synced 2026-04-26 12:45:52 +03:00
[PR #596] [MERGED] Automatically refresh access tokens in OAuthSwiftClient #687
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#687
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?
📋 Pull Request Information
Original PR: https://github.com/OAuthSwift/OAuthSwift/pull/596
Author: @Timac
Created: 5/12/2020
Status: ✅ Merged
Merged: 5/24/2020
Merged by: @phimage
Base:
master← Head:feature/AutomaticallyRefreshAccessTokens📝 Commits (2)
d530930Automatically refresh access tokens in OAuthSwiftClient6ce5debFix swiftlint warnings introduced ingithub.com/OAuthSwift/OAuthSwift@94f98f745f📊 Changes
5 files changed (+146 additions, -93 deletions)
View changed files
📝
Sources/OAuth2Swift.swift(+5 -77)📝
Sources/OAuthLogProtocol.swift(+12 -12)📝
Sources/OAuthSwift.swift(+3 -3)📝
Sources/OAuthSwiftClient.swift(+125 -0)📝
Sources/OAuthSwiftCredential.swift(+1 -1)📄 Description
Summary
Access tokens have an expiration date but OAuthSwift doesn't automatically refresh access tokens by default.
This PR proposes a solution:
Related links:
Changes:
requestWithAutomaticAccessTokenRenewalin OAuthSwiftClient. When used, it automatically refreshes the access token if it expired and restart the query.renewAccessTokenandrequestOAuthAccessTokenfrom OAuth2Swift to OAuthSwiftClient. The methodsrenewAccessTokenandrequestOAuthAccessTokenare still available in OAuth2Swift but they simply forward the call to OAuthSwiftClient to ensure that old apps don't need to be changed.Why?
I developed an application, called Clatters, that needs to access various services relying on OAuth. Rather that creating my own OAuth library, I decided to use OAuthSwift as it perfectly fit my needs.
However I believe that OAuthSwift should automatically refresh access tokens when they expire. The app itself shouldn't have to implement the logic to handle expired token.
Clatters has been available in the iOS App Store since February 2020 and relies on the code written in this PR.
Usage
You can call the convenient method
requestWithAutomaticAccessTokenRenewalin OAuthSwiftClient with the correct parameters. If the access token expired,requestWithAutomaticAccessTokenRenewalwill automatically renew the access token and retry the query. Here is an example to perform a query on Reddit:Notes
I wanted to keep the changes proposed in this PR really simple. As previously mentioned:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.