@@ -29,6 +29,7 @@ public struct CredentialsManager {
2929 private let storage : CredentialsStorage
3030 private let storeKey : String
3131 private let authentication : Authentication
32+ private let allowsAutoRefreshing : Bool
3233 private let dispatchQueue = DispatchQueue ( label: " com.auth0.credentialsmanager.serial " )
3334 #if WEB_AUTH_PLATFORM
3435 var bioAuth : BioAuthentication ?
@@ -40,12 +41,15 @@ public struct CredentialsManager {
4041 /// - authentication: Auth0 Authentication API client.
4142 /// - storeKey: Key used to store user credentials in the Keychain. Defaults to 'credentials'.
4243 /// - storage: The ``CredentialsStorage`` instance used to manage credentials storage. Defaults to a standard `SimpleKeychain` instance.
44+ /// - allowsAutoRefreshing: If `true` (the default), `CredentialsManager` will automatically attempt to refresh credentials using a refresh token.
4345 public init ( authentication: Authentication ,
4446 storeKey: String = " credentials " ,
45- storage: CredentialsStorage = SimpleKeychain ( ) ) {
47+ storage: CredentialsStorage = SimpleKeychain ( ) ,
48+ allowsAutoRefreshing: Bool = true ) {
4649 self . storeKey = storeKey
4750 self . authentication = authentication
4851 self . storage = storage
52+ self . allowsAutoRefreshing = allowsAutoRefreshing
4953 }
5054
5155 /// Retrieves the user information from the Keychain synchronously, without checking if the credentials are expired.
@@ -78,7 +82,7 @@ public struct CredentialsManager {
7882 /// Touch ID, but also allow fallback to passcode.
7983 ///
8084 /// ```swift
81- /// credentialsManager.enableBiometrics(withTitle: "Unlock with Face ID or passcode",
85+ /// credentialsManager.enableBiometrics(withTitle: "Unlock with Face ID or passcode",
8286 /// evaluationPolicy: .deviceOwnerAuthentication)
8387 /// ```
8488 ///
@@ -147,7 +151,7 @@ public struct CredentialsManager {
147151 /// result containing a ``CredentialsManagerError/revokeFailed`` error.
148152 ///
149153 /// ## Usage
150- ///
154+ ///
151155 /// ```swift
152156 /// credentialsManager.revoke { result in
153157 /// switch result {
@@ -240,12 +244,13 @@ public struct CredentialsManager {
240244 /// - Returns: If there are credentials stored containing a refresh token.
241245 public func canRenew( ) -> Bool {
242246 guard let credentials = self . retrieveCredentials ( ) else { return false }
243- return credentials. refreshToken != nil
247+ return self . allowsAutoRefreshing && credentials. refreshToken != nil
244248 }
245249
246250 #if WEB_AUTH_PLATFORM
247- /// Retrieves credentials from the Keychain and automatically renews them using the refresh token if the access
248- /// token is expired. Otherwise, the retrieved credentials will be returned via the success case as they are still
251+ /// Retrieves credentials from the Keychain and automatically renews them (if `allowsAutoRefreshing` is true)
252+ /// using the refresh token if the access token is expired.
253+ /// Otherwise, the retrieved credentials will be returned via the success case as they are still
249254 /// valid. Renewed credentials will be stored in the Keychain. **This method is thread-safe**.
250255 ///
251256 /// ## Usage
@@ -652,6 +657,11 @@ public struct CredentialsManager {
652657 dispatchGroup. leave ( )
653658 return callback ( . success( credentials) )
654659 }
660+
661+ guard self . allowsAutoRefreshing else {
662+ dispatchGroup. leave ( )
663+ return callback ( . failure( . renewNotSupported) )
664+ }
655665 guard let refreshToken = credentials. refreshToken else {
656666 dispatchGroup. leave ( )
657667 return callback ( . failure( . noRefreshToken) )
0 commit comments