Bionic Docs

iOS quickstart

Sign people in from an iOS app with the BionicNativeLogin Swift package.

Native preview Available for self-serve evaluation after domain verification. End-to-end acceptance on independent physical devices is pending.

BionicNativeLogin opens the system authentication session, brings the person back to your app and collects the session your server issued. It returns your own session type; it never stores, refreshes or invents session fields.

You'll need: iOS 17.4+, Swift Package Manager, and the native server adapter running on your backend with this app registered.

Add the package

Download the Swift SDK preview from your verified test app. Extract the archive and add client/ as a local SwiftPM dependency and select the BionicNativeLogin product. It has no third-party dependencies.

Set up the associated domain

The HTTPS callback only works once iOS trusts your domain for your app.

  1. In the signing profile, enable Associated Domains and add webcredentials:login.example.com. applinks alone isn't enough.
  2. Serve https://login.example.com/.well-known/apple-app-site-association over HTTPS, with a JSON content type and no redirect:
apple-app-site-association
{
  "webcredentials": { "apps": ["TEAMID.com.example.app"] },
  "applinks": {
    "details": [
      { "appIDs": ["TEAMID.com.example.app"], "components": [{ "/": "/bionic/ios" }] }
    ]
  }
}
  1. To handle returns after iOS has relaunched your app, also add applinks:login.example.com and route only that path to handleCallback(_:). Don't add a wildcard custom URL handler.

Configure and sign in

import BionicNativeLogin

struct AppSession: Decodable { let sessionToken: String } // your server's format

let configuration = try NativeLoginConfiguration(
    rpOrigin: URL(string: "https://api.example.com")!,
    appID: "com.example.app.ios.production",
    returnURL: URL(string: "https://login.example.com/bionic/ios")!
)

let login = BionicNativeLogin<AppSession>(
    configuration: configuration,
    browser: SystemAuthenticationBrowser(presentationAnchor: { appWindow }),
    storage: KeychainPendingAttemptStorage(
        service: "com.example.app.bionic.pending",
        account: configuration.appID
    ),
    decodeSessionPayload: { try JSONDecoder().decode(AppSession.self, from: $0) }
)

let session = try await login.signIn()
try await existingSessionManager.accept(session) // your app's session manager

appID and returnURL must match the app's entry in the server adapter. Keep the login object alive while sign-in runs; its APIs run on the main actor.

Handle interruptions

SituationWhat to call
Network failure during sign-inOffer a retry that calls login.resume().
The person cancelslogin.cancel()
iOS relaunched your app and delivered the callbacklogin.handleCallback(url) for your registered path only
Sign-in failed before it startedlogin.cancel() to clear local state, then sign in again

signIn() already handles the callback from the active authentication session, so don't deliver it twice. Logging out of your app goes through your own logout endpoint, not cancel().

Test on a device

Check the signed app, the association download, callback delivery, cancellation, killing the app mid-sign-in and recovery on real iOS 17.4+ devices. Success in the simulator doesn't prove the association works. After the return, use the issued session to read a protected backend route. Sign out with your app’s session manager and verify the same route requires authentication.

What the SDK stores

The Keychain holds only the temporary sign-in material (verifier, state, code and attempt) with kSecAttrAccessibleWhenUnlockedThisDeviceOnly. Nothing syncs or migrates through backups, and it's removed once sign-in completes, is cancelled or expires. Your session manager decides how your own credentials are stored.

Don't log callback URLs, codes, verifiers or decoded session payloads. SDK errors contain fixed codes and a sanitized request ID.

Scope

System authentication only: no embedded web view or custom URL scheme fallback. Desktop sign-in isn't supported. The macOS target exists only for protocol tests.

On this page