@@ -32,10 +32,17 @@ public struct CredentialsManager {
3232 private let dispatchQueue = DispatchQueue ( label: " com.auth0.credentialsmanager.serial " )
3333 #if WEB_AUTH_PLATFORM
3434 var bioAuth : BioAuthentication ?
35- // Biometric session management
36- private static let noSession : TimeInterval = - 1
37- private static var lastBiometricAuthTime : TimeInterval = noSession
38- private static let sessionLock = NSLock ( )
35+ // Biometric session management - using a class to allow mutation in non-mutating methods
36+ private final class BiometricSession {
37+ let noSession : TimeInterval = - 1
38+ var lastBiometricAuthTime : TimeInterval = - 1
39+ let lock = NSLock ( )
40+
41+ init ( ) {
42+ lastBiometricAuthTime = noSession
43+ }
44+ }
45+ private let biometricSession = BiometricSession ( )
3946 #endif
4047
4148 /// Creates a new `CredentialsManager` instance.
@@ -140,7 +147,9 @@ public struct CredentialsManager {
140147 /// - Returns: If the credentials were removed.
141148 public func clear( ) -> Bool {
142149 #if WEB_AUTH_PLATFORM
143- Self . clearBiometricSession ( )
150+ self . biometricSession. lock. lock ( )
151+ self . biometricSession. lastBiometricAuthTime = self . biometricSession. noSession
152+ self . biometricSession. lock. unlock ( )
144153 #endif
145154 return self . storage. deleteEntry ( forKey: self . storeKey)
146155 }
@@ -172,11 +181,11 @@ public struct CredentialsManager {
172181 public func isBiometricSessionValid( ) -> Bool {
173182 guard let bioAuth = self . bioAuth else { return false }
174183
175- Self . sessionLock . lock ( )
176- defer { Self . sessionLock . unlock ( ) }
184+ self . biometricSession . lock . lock ( )
185+ defer { self . biometricSession . lock . unlock ( ) }
177186
178- let lastAuth = Self . lastBiometricAuthTime
179- if lastAuth == Self . noSession { return false }
187+ let lastAuth = self . biometricSession . lastBiometricAuthTime
188+ if lastAuth == self . biometricSession . noSession { return false }
180189
181190 switch bioAuth. policy {
182191 case . session( let timeoutInSeconds) , . appLifecycle( let timeoutInSeconds) :
@@ -193,12 +202,12 @@ public struct CredentialsManager {
193202 /// ## Usage
194203 ///
195204 /// ```swift
196- /// CredentialsManager .clearBiometricSession()
205+ /// credentialsManager .clearBiometricSession()
197206 /// ```
198- public static func clearBiometricSession( ) {
199- sessionLock . lock ( )
200- defer { sessionLock . unlock ( ) }
201- lastBiometricAuthTime = noSession
207+ public func clearBiometricSession( ) {
208+ self . biometricSession . lock . lock ( )
209+ defer { self . biometricSession . lock . unlock ( ) }
210+ self . biometricSession . lastBiometricAuthTime = self . biometricSession . noSession
202211 }
203212 #endif
204213
@@ -392,7 +401,7 @@ public struct CredentialsManager {
392401 }
393402
394403 // Update biometric session after successful authentication (only for session-based policies)
395- Self . updateBiometricSession ( for: bioAuth. policy)
404+ self . updateBiometricSession ( for: bioAuth. policy)
396405
397406 self . retrieveCredentials ( scope: scope,
398407 minTTL: minTTL,
@@ -1582,15 +1591,15 @@ public extension CredentialsManager {
15821591 #if WEB_AUTH_PLATFORM
15831592 /// Updates the biometric session timestamp to the current time.
15841593 /// Only updates for session-based policies (Session and AppLifecycle).
1585- private static func updateBiometricSession( for policy: BiometricPolicy ) {
1594+ private func updateBiometricSession( for policy: BiometricPolicy ) {
15861595 // Don't update session for "Always" policy
15871596 switch policy {
15881597 case . always:
15891598 return
15901599 case . session, . appLifecycle:
1591- sessionLock . lock ( )
1592- defer { sessionLock . unlock ( ) }
1593- lastBiometricAuthTime = Date ( ) . timeIntervalSince1970
1600+ self . biometricSession . lock . lock ( )
1601+ defer { self . biometricSession . lock . unlock ( ) }
1602+ self . biometricSession . lastBiometricAuthTime = Date ( ) . timeIntervalSince1970
15941603 }
15951604 }
15961605 #endif
0 commit comments