Bionic Docs

Native server adapter

One backend adapter that connects the Swift and Kotlin SDKs to your existing accounts and sessions.

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

@bionic/login-kit/native-server runs on your HTTPS server and serves both native SDKs. It handles the sign-in proof, the browser binding and the one-time handoff back to your app. Your code decides which account the identity belongs to and issues your own session; the app receives that session over HTTPS, never inside the return URL.

A backendless app can't use this integration: it needs a server and a session interface.

You'll need: Node 22, PostgreSQL 16+ with pg 8.16.3 or Prisma 6.19.2, HTTPS, a registration with a callback dedicated to native sign-in, and a 32-byte encryption key from your secret manager.

Install the adapter from either native preview

Download the Swift or Kotlin archive from your verified test app. Copy its server/ directory into your Node project and run npm install ./server/login-kit.tgz from that project. Follow server/NATIVE-RP.md. The installed example is at node_modules/@bionic/login-kit/example/native-rp/integration.mjs.

Apply the native schema

Apply the packaged SQL at node_modules/@bionic/login-kit/sql/native-login-v1.sql to your app database. The adapter exports nativeServerSchema, which adds only native sign-in attempts and proof transaction data. Apply it through your migration process; it never runs on startup.

Register your apps

Each entry in apps describes one app in one environment:

const registeredApps = [
  {
    appId: 'com.example.app.ios.production',
    name: 'Example',
    returnUri: 'https://login.example.com/bionic/ios',
    association: { platform: 'ios', teamId: 'TEAMID', bundleId: 'com.example.app' },
  },
  {
    appId: 'com.example.app.android.production',
    name: 'Example',
    returnUri: 'https://login.example.com/bionic/android',
    association: {
      platform: 'android',
      packageName: 'com.example.app',
      sha256Certificates: ['AB:CD:…'],
    },
  },
];

Return URIs are exact HTTPS URLs with a path and no query or fragment. App IDs are public routing data, not app authentication: verify that you own each association before enabling it.

Create the handlers

import {
  createNativeHandlers,
  createPostgresNativeStore,
} from '@bionic/login-kit/native-server';

const handlers = createNativeHandlers({
  config: bionicConfig,
  apps: registeredApps,
  store: createPostgresNativeStore({ database, encryptionKey: receiptKey }),
  rateLimit: rpRateLimit,
  async completeNativeSignIn(tx, context) {
    const user = await rpAccounts.resolve(tx.native, context.identity);
    const session = await rpSessions.createOrGet(tx.native, user, context.issuanceKey);
    return {
      userId: user.id,
      sessionId: session.id,
      credentials: session.payload,
    };
  },
});

bionicConfig, registeredApps, database, receiptKey, rpRateLimit, rpAccounts and rpSessions are yours. credentials is whatever your app's session manager expects, as a JSON object up to 64 KiB.

rateLimit({ action, request }) is required. In production it must enforce quotas shared across your instances.

Mount the routes

The handlers are standard Request → Response functions. Mount them in your router under the default prefix /auth/bionic/native:

RouteHandler
POST /auth/bionic/native/attemptshandlers.attempts
GET /auth/bionic/native/launchhandlers.launch
POST /auth/bionic/native/starthandlers.start
GET your registered native callback pathhandlers.callback
POST /auth/bionic/native/completehandlers.complete
POST /auth/bionic/native/redeemhandlers.redeem
POST /auth/bionic/native/cancelhandlers.cancel

basePath changes the prefix for every route. Set enabled: false to stop new attempts while letting existing ones finish.

Schedule maintenance

Call handlers.purge() and handlers.reconcile() from an authenticated job you already run. Never expose them as HTTP routes. Purge removes expired sign-in data; reconcile resolves sessions whose outcome was unknown.

Issuing sessions

Choose one of two modes.

completeNativeSignIn(tx, { identity, appId, attemptId, issuanceKey }) returns { userId, sessionId, credentials }. Make every account and session write through tx.native, in the same transaction as the adapter's receipt. No network calls or other side effects: a rollback can run the callback again, and the guarantee is one committed session, not one execution.

To refuse a sign-in, for example when an account isn't eligible, throw NativeSignInRejected. The adapter records the rejection and the app receives invalid_completion; retries never call your hook again.

Timing

Limit
Sign-in attemptExpires 10 minutes after it starts
Completion codeExpires 60 seconds after the sign-in is verified
Retrying a redeemed sessionThe same result can be fetched again for 2 minutes

Errors

Every error carries an opaque request_id.

ErrorStatus
invalid_request400
invalid_completion401
attempt_conflict409
attempt_expired410
rate_limited429
temporarily_unavailable503

Don't log URLs containing launch tickets, request bodies, cookies, proofs, verifiers, completion codes or session payloads.

What it doesn't add

The adapter adds sign-in transport only. It has no Bionic access tokens, permission scopes, session refresh or global logout. Your app's session manager keeps owning storage, refresh, expiry and logout.

On this page