Choose your authentication path
Decide whether you’ll use Turnkey’s managed Auth Proxy (no backend required) or route auth through your own server.-
No backend (Auth Proxy)
- Your app talks directly to Turnkey’s Auth Proxy for OTP, OAuth, and signup.
- Origin validation, CORS, session lifetimes, and templates are centrally managed in the Dashboard.
- Proxy keys are HPKE-encrypted and decrypted only in-memory per request inside Turnkey’s enclave.
- The frontend calls Auth Proxy endpoints directly — no backend endpoints needed for OTP, OAuth, or signup flows.
- See the full details in the Auth Proxy reference.
-
Your backend
- Implement OTP, OAuth, and signup on your server using Turnkey’s public API.
- Keep custom validations, logging, and rate-limiting in your control; store user metadata alongside sub-orgs.
- Enable co-signing patterns (e.g., 2/2) from your backend.
- Follow the Swift guide: Advanced backend authentication.
TurnkeyContext (e.g., initOtp, verifyOtp, completeOtp, handleGoogleOAuth, handleAppleOAuth, handleDiscordOAuth, handleXOauth, and signUpWithPasskey) call the Auth Proxy and require an authProxyConfigId.
If you are using your own backend, omit authProxyConfigId in TurnkeyContext.configure and use your server endpoints; after your server returns a session JWT, store it via TurnkeyContext.storeSession(...).
Configuration
Before implementing any specific method, make sure you’ve:- Completed the Swift SDK Getting started guide
- Configured
TurnkeyContextwith yourorganizationIdand (if using Auth Proxy)authProxyConfigId - Set
rpIdand Associated Domains if you plan to use Passkeys - Optionally enabled managed auto-refresh for session state (
autoRefreshManagedState)
TurnkeyContext APIs when needed.
Persisting sessions
The Swift SDK generates an on-device API key pair to back your session:- When available, keys are created in the Secure Enclave and the private key material remains non-exportable and hardware-backed. Signing operations occur inside the enclave, via enclave-to-enclave communication within Turnkey’s infrastructure.
- If the Secure Enclave isn’t available on the device, the SDK falls back to secure storage using the iOS Keychain with appropriate access control.
Authentication state
Use the sharedTurnkeyContext to observe authentication and react in your UI by observing the authState property.
In the Swift SDK, AuthState represents where you are in the authentication lifecycle:
- Loading: set while the context is initializing. At this point, the SDK hasn’t yet determined whether a valid session exists.
- Authenticated: set as soon as a valid session is detected and the client is configured to make authenticated requests to Turnkey.
- Unauthenticated: set once the SDK determines no session exists.
authState, session, user, wallets), so your views can stay reactive and minimal.
Customize sub-organization creation
You can tailor default user and wallet creation settings by:- Passing
CreateSubOrgParamsto signup helpers (e.g., OTP or passkey signup), or - Providing defaults via
TurnkeyConfig.Auth.createSuborgParams