Quickstarts / Mobile App / iOS

iOS (Swift) Quickstart

Add X-Auth to a SwiftUI or UIKit app via Swift Package Manager. Call advice() from a tap handler with full async/await ergonomics.

Package: github.com/xentranet/x-auth-ios iOS 16+ · Swift 5.9+ Time: ~6 min
1

Add the Swift Package

In Xcode: File → Add Package Dependencies… and paste the URL. Or add it to Package.swift:

Package.swift
.package(url: "https://github.com/xentranet/x-auth-ios", from: "1.0.0")
2

Construct an XAuth instance

Build the SDK once, hold it in your app's environment.

App.swift
import SwiftUI
import XAuth

@main
struct TransferApp: App {
    let xauth = XAuth(tenantId: "your-app")

    var body: some Scene {
        WindowGroup {
            TransferView().environment(xauth)
        }
    }
}
3

Call advice() from a SwiftUI button

Pull the SDK from the environment, call advice, and POST the bearer to your backend.

TransferView.swift
import SwiftUI
import XAuth

struct TransferView: View {
    @Environment(XAuth.self) var xauth

    var body: some View {
        Button("Transfer $29.99") {
            Task {
                let advice = try await xauth.advice(
                    action: "transfer", amount: 2999, currency: "USD"
                )
                guard advice.decision == .allow else { return }

                var req = URLRequest(url: URL(string: "https://api.example.com/transfer")!)
                req.httpMethod = "POST"
                req.setValue("Bearer \(advice.accessToken)",
                             forHTTPHeaderField: "Authorization")
                _ = try await URLSession.shared.data(for: req)
            }
        }
    }
}
4

Verify on your backend

Use any backend SDK to call verify() and assert the bound action matches.

api/transfer.ts (Node example)
const { transaction_ctx } = await xauth.verify(bearer, {
  expect: { action: 'transfer', amount: req.body.amount },
});

Pair with a backend quickstart: Express, Go, Spring Boot, ASP.NET.

Next steps

Configure step-up methods (FaceID for biometric, push for out-of-band) and tune your risk policy.