OathKeychainStorage
public final class OathKeychainStorage : OathStorage, @unchecked Sendable
Keychain-based storage implementation for OATH credentials. Uses iOS Keychain Services for secure credential storage.
This implementation stores credential metadata and secrets separately in the iOS Keychain. Credential metadata is stored as JSON data, while secrets are stored as secure keychain items with appropriate accessibility settings.
Note
This class is thread-safe and handles concurrent access properly.-
Creates a new keychain storage instance.
Declaration
Swift
public init( service: String = "com.pingidentity.oath", logger: Logger? = nil, securityOptions: OathKeychainSecurityOptions = .standard )Parameters
serviceThe keychain service identifier. Defaults to “com.pingidentity.oath”.
loggerOptional logger for storage operations.
securityOptionsSecurity configuration for keychain operations. Defaults to standard security.
-
Creates a new keychain storage instance with individual security parameters (convenience).
Declaration
Swift
public convenience init( service: String = "com.pingidentity.oath", logger: Logger? = nil, accessGroup: String? = nil, accessibility: CFString = kSecAttrAccessibleWhenUnlockedThisDeviceOnly )Parameters
serviceThe keychain service identifier. Defaults to “com.pingidentity.oath”.
loggerOptional logger for storage operations.
accessGroupOptional keychain access group for shared access.
accessibilityKeychain accessibility level. Defaults to kSecAttrAccessibleWhenUnlockedThisDeviceOnly.
-
storeOathCredential(_:Asynchronous) Store an OATH credential in the keychain.
Throws
OathStorageError.storageFailureif keychain operations fail.Declaration
Swift
public func storeOathCredential(_ credential: OathCredential) async throwsParameters
credentialThe OATH credential to store.
-
retrieveOathCredential(credentialId:Asynchronous) Retrieve an OATH credential from the keychain.
Throws
OathStorageError.storageFailureif keychain operations fail.Declaration
Swift
public func retrieveOathCredential(credentialId: String) async throws -> OathCredential?Parameters
credentialIdThe ID of the credential to retrieve.
Return Value
The credential if found, nil otherwise.
-
getAllOathCredentials()AsynchronousGet all OATH credentials from the keychain.
Throws
OathStorageError.storageFailureif keychain operations fail.Declaration
Swift
public func getAllOathCredentials() async throws -> [OathCredential]Return Value
Array of all stored credentials.
-
removeOathCredential(credentialId:Asynchronous) Remove an OATH credential from the keychain.
Throws
OathStorageError.storageFailureif keychain operations fail.Declaration
Swift
public func removeOathCredential(credentialId: String) async throws -> BoolParameters
credentialIdThe ID of the credential to remove.
Return Value
true if removed, false if not found.
-
clearOathCredentials()AsynchronousClear all OATH credentials from the keychain.
Throws
OathStorageError.storageFailureif keychain operations fail.Declaration
Swift
public func clearOathCredentials() async throws -
getCredentialByIssuerAndAccount(issuer:AsynchronousaccountName: ) Retrieve an OATH credential by issuer and account name.
Throws
OathStorageError.storageFailureif keychain operations fail.Declaration
Swift
public func getCredentialByIssuerAndAccount(issuer: String, accountName: String) async throws -> OathCredential?Parameters
issuerThe issuer of the credential.
accountNameThe account name of the credential.
Return Value
The credential if found, nil otherwise.
View on GitHub