@@ -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.
@@ -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