Docs

Swift: Authentication

Sign app users in with passwords, magic links, SMS and email codes, OAuth/SSO and passkeys; keep and refresh the session; handle deep links with the Swift SDK.

Updated Oct 24, 2026

Sign app users in with passwords, magic links, SMS and email codes, OAuth/SSO and passkeys; keep and refresh the session; handle deep links. Every call runs as the client's signed-in user, so your project's policies and row-level security apply. Types and members are listed in source order; each one links to its HTTP endpoint where it maps to one.

#Types and members

SovariaAuth

Sign-in, sign-up and the session for an app user. Mirrors the Dart/TS/Python clients.

public final class SovariaAuth: @unchecked Sendable

SovariaAuth.currentSession

A property.

public var currentSession: Session?

SovariaAuth.passkeys

Passkeys (WebAuthn): add one for the signed-in user, sign in with one, list and remove them.

public var passkeys: SovariaPasskeys

SovariaAuth.changes

Emits sign-in / refresh / sign-out events (for updating UI).

public var changes: AsyncStream<AuthState>

Each new listener first gets .initialSession with the current session (nil when signed out), as in the Dart and TypeScript clients.

SovariaAuth.restoreSession

public func restoreSession() async throws -> Session?

SovariaAuth.currentAccessToken

The token to sign requests with: the session's (refreshed first when near expiry) or nil.

public func currentAccessToken() async -> String?

SovariaAuth.refreshSession

public func refreshSession(silent: Bool = false) async throws -> Session?

SovariaAuth.signUp

public func signUp(email: String, password: String, name: String = "") async throws -> [String: Any]

SovariaAuth.signInWithPassword

public func signInWithPassword(email: String, password: String, captchaToken: String? = nil) async throws -> Session

SovariaAuth.signInAnonymously

public func signInAnonymously() async throws -> Session

SovariaAuth.verifyMfa

public func verifyMfa(_ code: String, method: String = "") async throws -> Session

SovariaAuth.sendSmsOtp

public func sendSmsOtp(_ phone: String) async throws

SovariaAuth.verifySmsOtp

public func verifySmsOtp(phone: String, code: String) async throws -> Session

SovariaAuth.verifyEmailCode

public func verifyEmailCode(email: String, code: String) async throws -> Session

SovariaAuth.resetPasswordForEmail

Email a password-reset link (PKCE-bound when it opens your app).

public func resetPasswordForEmail(_ email: String, redirectTo: String? = nil, pkce: Bool? = nil) async throws

SovariaAuth.confirmPasswordReset

Set the new password with the token from a type=recovery link.

public func confirmPasswordReset(token: String, newPassword: String, codeVerifier: String? = nil) async throws

SovariaAuth.getOAuthSignInURL

Where the OAuth sign-in should take the user (an app scheme such as com.acme.app://callback, or a web URL).

public func getOAuthSignInURL(_ provider: String, redirectTo: String? = nil) async throws -> OAuthStart

Asks for the JSON answer (the route redirects otherwise) and starts PKCE: the verifier is kept in the session storage until exchangeCodeForSession (audit SDK2-M2).

SovariaAuth.exchangeCodeForSession

Finish an OAuth sign-in with the code from the redirect.

public func exchangeCodeForSession(_ code: String, codeVerifier: String? = nil) async throws -> Session

The PKCE verifier saved by getOAuthSignInURL is used when none is passed.

SovariaAuth.listProviders

public func listProviders() async throws -> [[String: Any]]

SovariaAuth.getUser

public func getUser() async throws -> [String: Any]

SovariaAuth.listDevices

public func listDevices() async throws -> [[String: Any]]

SovariaAuth.signOut

public func signOut() async throws

AuthState

public struct AuthState: @unchecked Sendable

AuthState.event

A property.

public let event: AuthEvent

AuthState.session

A property.

public let session: Session?

AuthLinkResult

What an auth link did. type is sso, magiclink, recovery, signup, email_change_current or email_change_new; session is set when the link signed the user in; for recovery pass token to confirmPasswordReset with the new password.

public struct AuthLinkResult: @unchecked Sendable

AuthLinkResult.type

A property.

public let type: String

AuthLinkResult.session

A property.

public let session: Session?

AuthLinkResult.token

A property.

public let token: String?

AuthLinkResult.error

A property.

public let error: String?

AuthLinkResult.errorDescription

A property.

public let errorDescription: String?

OAuthStart

public struct OAuthStart: Sendable

OAuthStart.url

A property.

public let url: String

OAuthStart.codeVerifier

A property.

public let codeVerifier: String?

SovariaPasskeys

Passkey calls. Run the platform ceremony with ASAuthorizationPlatformPublicKeyCredentialProvider (iOS 15+, macOS 12+): build its request from the options a start… call returns, then send the credential as WebAuthn JSON (base64url fields) to the matching finish… call.

public struct SovariaPasskeys: @unchecked Sendable

SovariaPasskeys.startRegistration

Registration options (WebAuthn JSON) for a new passkey for the signed-in user.

public func startRegistration(name: String = "") async throws -> [String: Any]

SovariaPasskeys.finishRegistration

Save the passkey the authenticator created (its WebAuthn JSON).

public func finishRegistration(credential: [String: Any], name: String = "") async throws -> [String: Any]

SovariaPasskeys.startSignIn

Sign-in options.

public func startSignIn(userId: String? = nil) async throws -> SignInStart

Pass userId to offer only that user's passkeys.

SovariaPasskeys.finishSignIn

Verify the signed challenge and sign the user in (two-factor when the device checked the user).

public func finishSignIn(challengeId: String, credential: [String: Any]) async throws -> Session

SovariaPasskeys.list

The signed-in user's passkeys: id, name, created_at, last_used_at.

public func list() async throws -> [[String: Any]]

SovariaPasskeys.remove

Remove one of the signed-in user's passkeys.

public func remove(_ passkeyId: String) async throws

SignInStart

public struct SignInStart: @unchecked Sendable

SignInStart.challengeId

A property.

public let challengeId: String

SignInStart.options

A property.

public let options: [String: Any]

Session

A signed-in app user's tokens.

public struct Session: @unchecked Sendable

Session.accessToken

A property.

public let accessToken: String

Session.refreshToken

A property.

public let refreshToken: String

Session.expiresAt

A property.

public let expiresAt: Date

Session.raw

The full token response (actor lane, MFA flags, …), minus the refresh token.

public let raw: [String: Any]

Session.Session.init

Create an instance.

public init(accessToken: String, refreshToken: String, expiresAt: Date, raw: [String: Any] = [:])

Session.userId

The user id (sub of the access token).

public var userId: String?

Session.claims

The access token's claims (not verified here; the server verifies on every request).

public var claims: [String: Any]

Session.expiresWithin

public func expiresWithin(_ margin: TimeInterval, now: Date = Date()) -> Bool

SessionStorage

Where the client keeps the session across launches. Use the Keychain in apps; the default keeps it in memory only (lost on relaunch).

public protocol SessionStorage: AnyObject, Sendable

SessionStorage.read

func read(_ key: String) async -> String?

SessionStorage.write

func write(_ key: String, _ value: String) async

SessionStorage.delete

func delete(_ key: String) async

MemorySessionStorage

public final class MemorySessionStorage: SessionStorage, @unchecked Sendable

MemorySessionStorage.MemorySessionStorage.init

Create an instance.

public init()

MemorySessionStorage.read

public func read(_ key: String) async -> String?

MemorySessionStorage.write

public func write(_ key: String, _ value: String) async

MemorySessionStorage.delete

public func delete(_ key: String) async

SovariaDevice

The device a session belongs to (sent as headers so sign-outs and attestation can target it).

public struct SovariaDevice: Sendable

SovariaDevice.id

A property.

public let id: String

SovariaDevice.platform

A property.

public let platform: String

SovariaDevice.name

A property.

public let name: String

SovariaDevice.SovariaDevice.init

Create an instance.

public init(id: String, platform: String, name: String = "")

AuthEvent

public enum AuthEvent: Sendable

Values: initialSession, signedIn, tokenRefreshed, signedOut, mfaRequired.

Pkce

A PKCE pair (RFC 7636, S256): keep verifier on the device, send challenge with the request.

public struct Pkce: Sendable

Pkce.verifier

A property.

public let verifier: String

Pkce.challenge

A property.

public let challenge: String

Pkce.generate

A fresh pair from 32 random bytes (a 43-character verifier).

public static func generate() -> Pkce

Pkce.challengeFor

BASE64URL(SHA-256(verifier)) without padding.

public static func challengeFor(_ verifier: String) -> String