[PR #219] [CLOSED] Autorenew OAuth2 access tokens #575

Closed
opened 2026-03-03 16:49:31 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/OAuthSwift/OAuthSwift/pull/219
Author: @FGoessler
Created: 4/5/2016
Status: Closed

Base: masterHead: #217-Autorenew-OAuth2-Tokens


📝 Commits (10+)

  • da78f59 #217 autorenew Oauth2 access tokens: created an extension on NSError to detect whether it was caused by an invalid access token
  • ffe3a94 #217 autorenew OAuth2 access tokens on every request via an OAuthSwiftClient
  • 6142484 #217 autorenew OAuth2 access tokens: created new callback property on OAuthSwiftClient to get informed about access token renewals
  • a773fd1 #217 autorenew OAuth2 access tokens: token expiration detection for Facebooks API
  • d286157 #217 autorenew OAuth2 access tokens: added unit test for autorenewal
  • 04593d2 #217 autorenew OAuth2 access tokens: added documentation comments
  • ef1288c #217 autorenew OAuth2 access tokens: refactored tokenExpirationHandler which now has an assert to not use it for OAuth1
  • 2db41a4 added the possibility to cancel requests which haven't been started yet
  • 63154b2 Refactoring to make the implementation of new features easier.
  • 83df2d7 Implemented a cancel method on OAuthSwiftTokenRefreshingRequest

📊 Changes

16 files changed (+981 additions, -500 deletions)

View changed files

📝 OAuthSwift.xcodeproj/project.pbxproj (+38 -0)
OAuthSwift/NSError+OAuthSwift.swift (+56 -0)
📝 OAuthSwift/OAuth1Swift.swift (+9 -7)
📝 OAuthSwift/OAuth2Swift.swift (+19 -23)
📝 OAuthSwift/OAuthSwift.swift (+7 -2)
📝 OAuthSwift/OAuthSwiftClient.swift (+73 -189)
📝 OAuthSwift/OAuthSwiftHTTPRequest.swift (+163 -147)
OAuthSwift/OAuthSwiftHTTPRequestConfig.swift (+123 -0)
📝 OAuthSwift/OAuthSwiftMultipartData.swift (+1 -1)
OAuthSwift/OAuthSwiftTokenRefreshingRequest.swift (+99 -0)
OAuthSwiftTests/NSErrorOAuthSwiftTest.swift (+63 -0)
📝 OAuthSwiftTests/OAuth2SwiftTests.swift (+8 -25)
📝 OAuthSwiftTests/OAuthSwiftClientTests.swift (+71 -69)
OAuthSwiftTests/OAuthSwiftHTTPRequestConfigTest.swift (+208 -0)
📝 OAuthSwiftTests/OAuthSwiftRequestTests.swift (+35 -34)
📝 OAuthSwiftTests/TestServer.swift (+8 -3)

📄 Description

This PR aims to make the access token renewal process transparent to clients of this library as discussed in #217.

The implementation differs from my proposed solution in the issue since the token renewal process is to tightly coupled with the OAuth2Swift class.
Now the OAuthSwiftClient exposes a callback property which can be set to handle expired/invalid tokens and will retry the request via the completion block. OAuth2Swift configures this property such that it requests a new access tokens with its refresh token and stores the new token.

In case a request failed the error response is checked if the cause is an invalid/expired token. Therefore I created an extension on NSError which I based on the code and specification in the Wiki. It also handles special cases for Facebook.

I would appreciate feedback about the convenience method startAuthorizedRequest(...) in OAuth2Swift which was introduced by @fabiomassimo. Since there was no release since this method was added it should be save to remove it, but for now I left it in and marked it as deprecated.

This PR also includes the changes to the unit tests done in #218 since I rebased this branch onto the other. I can perform a rebase on master as soon as the other PR is merged to make the merge and history nicer.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/OAuthSwift/OAuthSwift/pull/219 **Author:** [@FGoessler](https://github.com/FGoessler) **Created:** 4/5/2016 **Status:** ❌ Closed **Base:** `master` ← **Head:** `#217-Autorenew-OAuth2-Tokens` --- ### 📝 Commits (10+) - [`da78f59`](https://github.com/OAuthSwift/OAuthSwift/commit/da78f593b8f80ba7275746a78da726172a270d5d) #217 autorenew Oauth2 access tokens: created an extension on NSError to detect whether it was caused by an invalid access token - [`ffe3a94`](https://github.com/OAuthSwift/OAuthSwift/commit/ffe3a9456cb0538021a9a223f69a2760e82ea14f) #217 autorenew OAuth2 access tokens on every request via an OAuthSwiftClient - [`6142484`](https://github.com/OAuthSwift/OAuthSwift/commit/6142484787fb05e38e97866efc883a708bc75a36) #217 autorenew OAuth2 access tokens: created new callback property on OAuthSwiftClient to get informed about access token renewals - [`a773fd1`](https://github.com/OAuthSwift/OAuthSwift/commit/a773fd183df859435f6a27cf8f2857dee9bf5551) #217 autorenew OAuth2 access tokens: token expiration detection for Facebooks API - [`d286157`](https://github.com/OAuthSwift/OAuthSwift/commit/d28615776b299392d209731942c5501de7b34a49) #217 autorenew OAuth2 access tokens: added unit test for autorenewal - [`04593d2`](https://github.com/OAuthSwift/OAuthSwift/commit/04593d2be637f1b7d36949850e16d8318c1cf6ba) #217 autorenew OAuth2 access tokens: added documentation comments - [`ef1288c`](https://github.com/OAuthSwift/OAuthSwift/commit/ef1288c5b623e7cc54c507bc19d1fb9b6eb56fc6) #217 autorenew OAuth2 access tokens: refactored tokenExpirationHandler which now has an assert to not use it for OAuth1 - [`2db41a4`](https://github.com/OAuthSwift/OAuthSwift/commit/2db41a449a885683855ffbf949c86168c7cbc971) added the possibility to cancel requests which haven't been started yet - [`63154b2`](https://github.com/OAuthSwift/OAuthSwift/commit/63154b26bb53fcba3cb05ae3d9c6a38725f68204) Refactoring to make the implementation of new features easier. - [`83df2d7`](https://github.com/OAuthSwift/OAuthSwift/commit/83df2d7fdaa14325f2adfce12f7cfd7baa77bda7) Implemented a cancel method on OAuthSwiftTokenRefreshingRequest ### 📊 Changes **16 files changed** (+981 additions, -500 deletions) <details> <summary>View changed files</summary> 📝 `OAuthSwift.xcodeproj/project.pbxproj` (+38 -0) ➕ `OAuthSwift/NSError+OAuthSwift.swift` (+56 -0) 📝 `OAuthSwift/OAuth1Swift.swift` (+9 -7) 📝 `OAuthSwift/OAuth2Swift.swift` (+19 -23) 📝 `OAuthSwift/OAuthSwift.swift` (+7 -2) 📝 `OAuthSwift/OAuthSwiftClient.swift` (+73 -189) 📝 `OAuthSwift/OAuthSwiftHTTPRequest.swift` (+163 -147) ➕ `OAuthSwift/OAuthSwiftHTTPRequestConfig.swift` (+123 -0) 📝 `OAuthSwift/OAuthSwiftMultipartData.swift` (+1 -1) ➕ `OAuthSwift/OAuthSwiftTokenRefreshingRequest.swift` (+99 -0) ➕ `OAuthSwiftTests/NSErrorOAuthSwiftTest.swift` (+63 -0) 📝 `OAuthSwiftTests/OAuth2SwiftTests.swift` (+8 -25) 📝 `OAuthSwiftTests/OAuthSwiftClientTests.swift` (+71 -69) ➕ `OAuthSwiftTests/OAuthSwiftHTTPRequestConfigTest.swift` (+208 -0) 📝 `OAuthSwiftTests/OAuthSwiftRequestTests.swift` (+35 -34) 📝 `OAuthSwiftTests/TestServer.swift` (+8 -3) </details> ### 📄 Description This PR aims to make the access token renewal process transparent to clients of this library as discussed in #217. The implementation differs from my proposed solution in the issue since the token renewal process is to tightly coupled with the `OAuth2Swift` class. Now the `OAuthSwiftClient` exposes a callback property which can be set to handle expired/invalid tokens and will retry the request via the completion block. `OAuth2Swift` configures this property such that it requests a new access tokens with its refresh token and stores the new token. In case a request failed the error response is checked if the cause is an invalid/expired token. Therefore I created an extension on NSError which I based on the code and specification in the [Wiki](https://github.com/OAuthSwift/OAuthSwift/wiki/OAuth-2.0-Token-Expiration). It also handles special cases for Facebook. I would appreciate feedback about the convenience method `startAuthorizedRequest(...)` in `OAuth2Swift` which was introduced by @fabiomassimo. Since there was no release since this method was added it should be save to remove it, but for now I left it in and marked it as deprecated. This PR also includes the changes to the unit tests done in #218 since I rebased this branch onto the other. I can perform a rebase on master as soon as the other PR is merged to make the merge and history nicer. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-03 16:49:31 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#575
No description provided.