Overview
This guide shows how to implement passkey authentication in a Swift app using the Turnkey Swift SDK.You’ll add the required platform configuration, set
rpId, and call loginWithPasskey and signUpWithPasskey from your UI. The examples below use SwiftUI, but the SDK works with any Swift framework.
Passkey setup
To enable passkeys on iOS, configure Associated Domains and provide anrpId that matches your domain.
- Add Associated Domains in Xcode (Signing & Capabilities → Associated Domains):
webcredentials:yourdomain.com
- For details, see Apple’s docs on Associated Domains.
Set rpId in your SDK configuration
Ensure TurnkeyConfig has an rpId matching your Associated Domain, and set organizationId for login.
Usage
Below are examples for signing up and logging in with passkeys:Log in with passkey
Before callingloginWithPasskey, you must provide an ASPresentationAnchor.
Apple requires a presentation context so the system can display the passkey UI in the correct window.
We use a helper (defaultAnchor()) to resolve the active key window for this purpose.
- Does not use Auth Proxy:
loginWithPasskeyruns entirely on-device and talks directly to Turnkey’s API using a stamp; no Auth Proxy involvement. - Session expiration: You can pass
expirationSecondsto set the session lifetime. If omitted, the SDK resolves it in this order:- Dashboard setting (when an Auth Proxy config is present and
sessionExpirationSecondsis set), else - Default of 900 seconds (15 minutes).
- Dashboard setting (when an Auth Proxy config is present and
Sign up with passkey
signUpWithPasskeyrequires the Auth Proxy to be configured (authProxyConfigId), since signup creates a new sub-organization and user.- You can customize the passkey display name during signup:
Tips
- Ensure your
rpIdexactly matches the domain configured in Associated Domains; otherwise passkey operations will fail. - Confirm your provisioning profile includes Associated Domains and your build contains the entitlements.