Store
public struct Store
Shared Web Credentials Store.
Supports reading, adding, and removing shared web credentials. There is also a utility method for generating a new password.
-
Completion block for reading from shared web credentials.
Note
If the error is
nil, the array will not be empty.Declaration
Swift
public typealias ReadCompletion = (_ credential: Credential?, _ error: CFError?) -> VoidParameters
credentialsArray of credentials or
nil.errorSystem error or
nil. -
Completion block for writing to shared web credentials.
Note
If the error is
nil, the operation was a success.Declaration
Swift
public typealias WriteCompletion = (_ error: CFError?) -> VoidParameters
errorSystem error or
nil.
-
Asynchronously obtain one or more shared passwords for a website.
This function requests one or more shared passwords for a given website, depending on whether the optional account parameter is supplied. To obtain results, the website specified in the fqdn parameter must be one which matches an entry in the calling application’s
com.apple.developer.associated-domainsentitlement.Note
The system API
SecRequestSharedWebCredentialreturns an array ofCFDictionaryobjects for each result. In practice, you only ever get one dictionary in this array. The system UI shows all of the credentials you have saved, but makes you select just one. The one you select is the contents of the results array.Declaration
Swift
public static func get(domain: String? = nil, account: String? = nil, completion: @escaping ReadCompletion)Parameters
domainFully qualified domain name of the website for which passwords are being requested. If
nilis passed in this argument, the domain name(s) listed in the calling application’scom.apple.developer.associated-domainsentitlement are searched implicitly.accountAccount name for which passwords are being requested. The account may be
nilto request all shared credentials which are available for the site, allowing the caller to discover an existing account.completionA block which will be called to deliver the requested credential. If no matching items were found, the credential array will be
nil, and the CFErrorRef parameter will provide the error result. -
Asynchronously store (or update) a shared password for a website.
This function adds a shared password item which will be accessible by Safari and applications that have the specified fully-qualified domain name in their
com.apple.developer.associated-domainsentitlement. If a shared password item already exists for the specified website and account, it will be updated with the provided password.Note
Note:
Since a request involving shared web credentials may potentially require user interaction or other verification to be approved, this function is dispatched asynchronously; your code provides a completion handler that will be called once the results (if any) are available.
Declaration
Swift
public static func add(domain: String, account: String, password: String, completion: WriteCompletion? = nil)Parameters
domainThe fully qualified domain name of the website requiring the password.
accountThe account name associated with this password.
passwordThe password to be stored.
completionA block which will be invoked when the function has completed. If the shared password was successfully added, the CFErrorRef parameter passed to the block will be
nil. If the error parameter is non-nil, an error occurred and the error reference will hold the result. -
Asynchronously remove a shared password for a website.
This function remove a shared password item which will be accessible by Safari and applications that have the specified fully-qualified domain name in their
com.apple.developer.associated-domainsentitlement.Note
Note:
Since a request involving shared web credentials may potentially require user interaction or other verification to be approved, this function is dispatched asynchronously; your code provides a completion handler that will be called once the results (if any) are available.
Declaration
Swift
public static func remove(domain: String, account: String, completion: WriteCompletion? = nil)Parameters
domainThe fully qualified domain name of the website requiring the password.
accountThe account name associated with this password.
completionA block which will be invoked when the function has completed. If the shared password was successfully removed, the CFErrorRef parameter passed to the block will be
nil. If the error parameter is non-nil, an error occurred and the error reference will hold the result.
-
Returns a randomly generated password.
Declaration
Swift
public static func generatePassword() -> String?Return Value
Optional
Stringpassword in the formxxx-xxx-xxx-xxxwherexis taken from the sets"abcdefghkmnopqrstuvwxy","ABCDEFGHJKLMNPQRSTUVWXYZ","3456789"with at least one character from each set being present ornilif it failed.
View on GitHub
Install in Dash
Store Struct Reference