Add Authsignal to your Podfile:
pod 'Authsignal', '~> 0.1.7'
Swift Package Manager
Add authsignal-ios to the dependencies value of your Package.swift.
.package(url: "https://github.com/authsignal/authsignal-ios.git", .upToNextMajor(from: "0.1.7"))
let authsignal = Authsignal(clientID: "YOUR_TENANT_ID", baseURL: "YOUR_REGION_BASE_URL")
You can find your client or tenant ID in the Authsignal Portal.
You must specify the correct base URL for your tenant's region.
Adding a device credential
Before a device credential can be added, a token should be requested server-side via the
track call. This token can then be passed to the iOS SDK to authorise adding a new device credential for the authenticated user.
await authsignal.push.addCredential(token: token)
For more information on how to request a token see our server documentation.
Removing a device credential
Getting a challenge
let challengeId = await authsignal.push.getChallenge()
Updating a challenge
let approved: Bool = true // true if the user has approved the challenge
await authsignal.push.updateChallenge(challengeID: challengeId, approved: approved)
Registering a new passkey
To register a new passkey, you first need to request a token via track. If the user is new, create a record for them in your own DB and pass their ID to Authsignal server-side to get a token, which can then be passed to the iOS SDK along with their username.
await authsignal.passkey.signUp(token: token, userName: userName)
Authenticating with an existing passkey
To handle re-authenticating when the username is captured, lookup the user by their username in your backend and then pass their ID to track to get a token, which can then be passed to the iOS SDK.
let resultToken = await authsignal.passkey.signIn(token: initialToken)
The result token can then be used to determine the result of the challenge.
Using passkey autofill
You can also initiate a passkey challenge in cases where the username isn't known yet - for example when using passkey autofill.
let resultToken = await authsignal.passkey.signIn(autofill: true)
The result token will resolve once the user selects a passkey and completes the challenge.
For more detail on passkey autofill see Apple's documentation.
Cancelling a passkey challenge
If a passkey challenge has been initiated and is in a pending state, for example to support autofill, it can be cancelled at any time. This should be done before navigating away from the screen containing the autofill textfield or before performing a new passkey challenge.