Skip to content

Commit c39dddb

Browse files
Update Documentation and testing it in App Target
1 parent 8d9ffa2 commit c39dddb

File tree

5 files changed

+53
-19
lines changed

5 files changed

+53
-19
lines changed

App/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22
import Auth0
33

4-
@UIApplicationMain
4+
@main
55
class AppDelegate: UIResponder, UIApplicationDelegate {
66

77
var window: UIWindow?

App/ViewController.swift

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
11
import UIKit
22
import Auth0
33

4+
// MARK: - Swift 6 Sendability Test: CredentialsManager in Actor
5+
actor AuthService {
6+
let credentialsManager: CredentialsManager
7+
8+
init() {
9+
self.credentialsManager = CredentialsManager(authentication: Auth0.authentication())
10+
}
11+
12+
func fetchCredentials() async throws -> Credentials {
13+
// This method can be called across concurrency contexts eg. Actor
14+
return try await credentialsManager.credentials(withScope: "openid profile email",
15+
minTTL: 60,
16+
parameters: [:],
17+
headers: [:])
18+
}
19+
}
20+
421
class ViewController: UIViewController {
22+
23+
// Swift 6 test: CredentialsManager can be used within actors
24+
private let authService = AuthService()
525

626
@IBAction func login(_ sender: Any) {
727
Auth0
828
.webAuth()
929
.logging(enabled: true)
10-
.start {
11-
switch $0 {
30+
.start { [weak self] result in
31+
switch result {
1232
case .failure(let error):
1333
DispatchQueue.main.async {
14-
self.alert(title: "Error", message: "\(error)")
34+
self?.alert(title: "Error", message: "\(error)")
1535
}
1636
case .success(let credentials):
1737
DispatchQueue.main.async {
18-
self.alert(title: "Success",
38+
self?.alert(title: "Success",
1939
message: "Authorized and got a token \(credentials.accessToken)")
2040
}
41+
// Test: Fetch credentials from actor with custom scope
42+
Task {
43+
await self?.testFetchCredentials()
44+
}
2145
}
22-
print($0)
46+
print(result)
2347
}
2448
}
2549

@@ -34,6 +58,16 @@ class ViewController: UIViewController {
3458
}
3559
}
3660
}
61+
62+
// Additional test method to fetch credentials from actor
63+
func testFetchCredentials() async {
64+
do {
65+
let credentials = try await authService.fetchCredentials()
66+
print("Successfully fetched credentials within actor: \(credentials.accessToken)")
67+
} catch {
68+
print("Failed to fetch credentials: \(error)")
69+
}
70+
}
3771

3872
}
3973

Auth0.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3891,7 +3891,7 @@
38913891
PRODUCT_NAME = "$(TARGET_NAME)";
38923892
PROVISIONING_PROFILE = "";
38933893
PROVISIONING_PROFILE_SPECIFIER = "";
3894-
SWIFT_VERSION = 5.0;
3894+
SWIFT_VERSION = 6.0;
38953895
};
38963896
name = Debug;
38973897
};
@@ -3913,7 +3913,7 @@
39133913
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.OAuth2;
39143914
PRODUCT_NAME = "$(TARGET_NAME)";
39153915
PROVISIONING_PROFILE_SPECIFIER = "";
3916-
SWIFT_VERSION = 5.0;
3916+
SWIFT_VERSION = 6.0;
39173917
};
39183918
name = Release;
39193919
};

Auth0/CredentialsManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public struct CredentialsManager: Sendable {
3333
#if WEB_AUTH_PLATFORM
3434
var bioAuth: BioAuthentication?
3535
// Biometric session management - using a class to allow mutation in non-mutating methods
36-
// @unchecked Sendable is fine here as we are using lock to read and update lastBiometricAuthTime which is safe acorss threads.
36+
// @unchecked Sendable is fine here as we are using lock to read and update lastBiometricAuthTime which is safe across threads.
3737
private final class BiometricSession: @unchecked Sendable {
3838
let noSession: TimeInterval = -1
3939
var lastBiometricAuthTime: TimeInterval = -1

EXAMPLES.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,16 @@ The Credentials Manager utility allows you to securely store and retrieve the us
367367
let credentialsManager = CredentialsManager(authentication: Auth0.authentication())
368368
```
369369

370+
> [!CAUTION]
371+
> The Credentials Manager is not thread-safe, except for the following methods:
372+
>
373+
> - `credentials()`
374+
> - `apiCredentials()`
375+
> - `ssoCredentials()`
376+
> - `renew()`
377+
>
378+
> To avoid concurrency issues, do not call its non thread-safe methods and properties from different threads without proper synchronization.
379+
370380
> [!NOTE]
371381
> **Swift 6 Concurrency Support**: The Credentials Manager conforms to `Sendable` and can be safely used across concurrency contexts, including within actors.
372382
>
@@ -389,16 +399,6 @@ let credentialsManager = CredentialsManager(authentication: Auth0.authentication
389399
> }
390400
> ```
391401
392-
> [!CAUTION]
393-
> The Credentials Manager is not thread-safe, except for the following methods:
394-
>
395-
> - `credentials()`
396-
> - `apiCredentials()`
397-
> - `ssoCredentials()`
398-
> - `renew()`
399-
>
400-
> To avoid concurrency issues, do not call its non thread-safe methods and properties from different threads without proper synchronization.
401-
402402
### Store credentials
403403
404404
When your users log in, store their credentials securely in the Keychain. You can then check if their credentials are still valid when they open your app again.

0 commit comments

Comments
 (0)