Skip to content

Commit c666285

Browse files
committed
Solve some concurrency warnings
1 parent 794f0e5 commit c666285

24 files changed

+287
-207
lines changed

Sources/Base/OAuth2AuthConfig.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,14 @@ import UIKit
2626
/**
2727
Simple struct to hold settings describing how authorization appears to the user.
2828
*/
29-
public struct OAuth2AuthConfig {
29+
public struct OAuth2AuthConfig: Sendable {
3030

3131
/// Sub-stuct holding configuration relevant to UI presentation.
32-
public struct UI {
32+
public struct UI: Sendable {
3333

3434
/// Title to propagate to views handled by OAuth2, such as OAuth2WebViewController.
3535
public var title: String? = nil
3636

37-
/// By assigning your own UIBarButtonItem (!) you can override the back button that is shown in the iOS embedded web view (does NOT apply to `SFSafariViewController` or `ASWebAuthenticationSession`).
38-
@available(*, deprecated, message: "This will be removed in v6.")
39-
public var backButton: AnyObject? = nil
40-
41-
/// If true it makes the login cancellable, otherwise the cancel button is not shown in the embedded web view.
42-
@available(*, deprecated, message: "This will be removed in v6.")
43-
public var showCancelButton = true
44-
4537
/// Starting with iOS 9, `SFSafariViewController` will be used for embedded authorization instead of our custom class. You can turn this off here.
4638
public var useSafariView = false
4739

@@ -72,7 +64,7 @@ public struct OAuth2AuthConfig {
7264
/// Context information for the authorization flow:
7365
/// - iOS: The parent view controller to present from
7466
/// - macOS: An NSWindow from which to present a modal sheet _or_ `nil` to present in a new window
75-
public weak var authorizeContext: AnyObject? = nil
67+
public nonisolated(unsafe) weak var authorizeContext: (AnyObject)? = nil
7668

7769
/// UI-specific configuration.
7870
public var ui = UI()

Sources/Base/OAuth2AuthRequest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public enum OAuth2EndpointAuthMethod: String {
6666
/**
6767
Class representing an OAuth2 authorization request that can be used to create NSURLRequest instances.
6868
*/
69+
@OAuth2Actor
6970
open class OAuth2AuthRequest {
7071

7172
/// The url of the receiver. Queries may by added by parameters specified on `params`.

Sources/Base/OAuth2AuthorizerUI.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Foundation
2424
/**
2525
Platform-dependent authorizers must adopt this protocol.
2626
*/
27+
@OAuth2Actor
2728
public protocol OAuth2AuthorizerUI {
2829

2930
/// The OAuth2 instance this authorizer belongs to.
@@ -44,5 +45,5 @@ public protocol OAuth2AuthorizerUI {
4445
- parameter at: The authorize URL to open
4546
- throws: Can throw OAuth2Error if the method is unable to show the authorize screen
4647
*/
47-
func authorizeEmbedded(with config: OAuth2AuthConfig, at url: URL) throws
48+
func authorizeEmbedded(with config: OAuth2AuthConfig, at url: URL) async throws
4849
}

Sources/Base/OAuth2Base.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import Foundation
2222
import CommonCrypto
2323

2424

25+
@globalActor public actor OAuth2Actor : GlobalActor {
26+
public static let shared = OAuth2Actor()
27+
}
28+
2529
/**
2630
Class extending on OAuth2Requestable, exposing configuration and maintaining context, serving as base class for `OAuth2`.
2731
*/
@@ -202,18 +206,18 @@ open class OAuth2Base: OAuth2Securable {
202206
return authURL.description
203207
}
204208

205-
override open func updateFromKeychainItems(_ items: [String: Any]) {
209+
override open func updateFromKeychainItems(_ items: [String: any Sendable]) {
206210
for message in clientConfig.updateFromStorableItems(items) {
207211
logger?.debug("OAuth2", msg: message)
208212
}
209213
clientConfig.secretInBody = (clientConfig.endpointAuthMethod == OAuth2EndpointAuthMethod.clientSecretPost)
210214
}
211215

212-
override open func storableCredentialItems() -> [String: Any]? {
216+
override open func storableCredentialItems() -> [String: any Sendable]? {
213217
return clientConfig.storableCredentialItems()
214218
}
215219

216-
override open func storableTokenItems() -> [String: Any]? {
220+
override open func storableTokenItems() -> [String: any Sendable]? {
217221
return clientConfig.storableTokenItems()
218222
}
219223

Sources/Base/OAuth2ClientConfig.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ open class OAuth2ClientConfig {
209209

210210
- returns: A storable dictionary with credentials
211211
*/
212-
func storableCredentialItems() -> [String: Any]? {
212+
func storableCredentialItems() -> [String: any Sendable]? {
213213
guard let clientId = clientId, !clientId.isEmpty else { return nil }
214214

215-
var items: [String: Any] = ["id": clientId]
215+
var items: [String: any Sendable] = ["id": clientId]
216216
if let secret = clientSecret {
217217
items["secret"] = secret
218218
}
@@ -225,8 +225,8 @@ open class OAuth2ClientConfig {
225225

226226
- returns: A storable dictionary with token data
227227
*/
228-
func storableTokenItems() -> [String: Any]? {
229-
var items = [String: Any]()
228+
func storableTokenItems() -> [String: any Sendable]? {
229+
var items = [String: any Sendable]()
230230

231231
if let access = accessToken {
232232
items["accessToken"] = access

Sources/Base/OAuth2CustomAuthorizerUI.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/**
2323
Platform-dependent login presenters that present custom login views must adopt this protocol.
2424
*/
25+
@OAuth2Actor
2526
public protocol OAuth2CustomAuthorizerUI {
2627

2728
/**
@@ -31,7 +32,7 @@ public protocol OAuth2CustomAuthorizerUI {
3132
- parameter fromContext: The presenting context, typically another controller of platform-dependent type
3233
- parameter animated: Whether the presentation should be animated
3334
*/
34-
func present(loginController: AnyObject, fromContext context: AnyObject?, animated: Bool) throws
35+
func present(loginController: AnyObject, fromContext context: AnyObject?, animated: Bool) async throws
3536

3637
/**
3738
This function must dismiss the login controller.

Sources/Base/OAuth2DebugURLSessionDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Doing so is a REALLY BAD IDEA, even in development environments where you can us
2828
Still, sometimes you'll have to do this so this class is provided, but DO NOT SUBMIT your app using self-signed SSL certs to the App
2929
Store. You have been warned!
3030
*/
31-
open class OAuth2DebugURLSessionDelegate: NSObject, URLSessionDelegate {
31+
final class OAuth2DebugURLSessionDelegate: NSObject, URLSessionDelegate {
3232

3333
/// The host to allow a self-signed SSL certificate for.
3434
let host: String
@@ -42,7 +42,7 @@ open class OAuth2DebugURLSessionDelegate: NSObject, URLSessionDelegate {
4242
self.host = host
4343
}
4444

45-
open func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge,
45+
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge,
4646
completionHandler: @escaping (Foundation.URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
4747
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
4848
if challenge.protectionSpace.host == host, let trust = challenge.protectionSpace.serverTrust {

Sources/Base/OAuth2KeychainAccount.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020

2121
import Foundation
2222
#if !NO_KEYCHAIN_IMPORT // needs to be imported when using `swift build`, not when building via Xcode
23-
import SwiftKeychain
23+
@preconcurrency import SwiftKeychain
2424
#endif
2525

2626

2727
/**
2828
Keychain integration handler for OAuth2.
2929
*/
30+
@OAuth2Actor
3031
struct OAuth2KeychainAccount: KeychainGenericPasswordType {
3132

3233
/// The service name to use.
@@ -52,7 +53,7 @@ struct OAuth2KeychainAccount: KeychainGenericPasswordType {
5253
- parameter account: The account name to use
5354
- parameter data: Data that we want to store to the keychain
5455
*/
55-
init(oauth2: OAuth2Securable, account: String, data inData: [String: Any] = [:]) {
56+
init(oauth2: OAuth2Securable, account: String, data inData: [String: any Sendable] = [:]) {
5657
serviceName = oauth2.keychainServiceName()
5758
accountName = account
5859
accessMode = String(oauth2.keychainAccessMode)
@@ -74,7 +75,7 @@ extension KeychainGenericPasswordType {
7475

7576
- returns: A [String: Any] dictionary of data fetched from the keychain
7677
*/
77-
mutating func fetchedFromKeychain() throws -> [String: Any] {
78+
mutating func fetchedFromKeychain() throws -> [String: any Sendable] {
7879
do {
7980
try _ = fetchFromKeychain()
8081
return data

Sources/Base/OAuth2Logger.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ A simple protocol for loggers used in OAuth2.
6464
The `OAuth2DebugLogger` is a simple implementation that logs to stdout. If you need more sophisticated logging, just adapt this protocol
6565
and set your logger on the `OAuth2` instance you're using.
6666
*/
67+
@OAuth2Actor
6768
public protocol OAuth2Logger {
6869

6970
/// The logger's logging level.

Sources/Base/OAuth2RequestPerformer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Protocol for types that can perform `URLRequest`s.
1414

1515
The class `OAuth2DataTaskRequestPerformer` implements this protocol and is by default used by all `OAuth2` classes to perform requests.
1616
*/
17+
@OAuth2Actor
1718
public protocol OAuth2RequestPerformer {
1819

1920
/**

0 commit comments

Comments
 (0)