Writing

Designing an authentication SDK for five banks

An app has users. An SDK has consumers. And when the SDK verifies identity for banks, the consumers aren't really the engineers calling your API. They're the compliance teams, security auditors and release managers standing behind those engineers. Building BankID's SDK for that audience changed most of what I believed about API design. This is what I kept.

Your API surface is a liability, so make it small

Every public symbol is a promise you will keep for years. Our SDK does a lot: authentication, OTP verification, liveness detection, document capture, deep linking, and a dozen more flows, each shipping and versioning on its own. None of that complexity is the partner’s problem. All sixteen-plus flows sit behind one facade:

public final class BankID {

    public static func configure(_ configuration: Configuration) throws -> BankID

    public func startAuthentication(presenting: UIViewController) async throws -> AuthenticationResult
    public func startOTPVerification(presenting: UIViewController) async throws -> OTPResult
    public func startLivenessCheck(presenting: UIViewController) async throws -> LivenessResult
    public func startDocumentCapture(presenting: UIViewController) async throws -> DocumentResult
    public func handle(_ url: URL) -> Bool

    public var session: Session? { get }
    public func signOut() async
}

Everything else is internal: the logic inside each flow, the video encoding behind liveness, the transport to our backend. Not because it's secret, but because anything public gets depended on, and anything depended on stops being yours to change. Our rule was simple: a symbol becomes public when two banks need it, never when one might.

Versioning without trust

For most libraries, semantic versioning is a courtesy. For us it had real consequences: a breaking change means five banks re-run their security review, and a bank that can't upgrade is a bank running without our latest liveness and fraud fixes. So compatibility had to be something we checked, not something we hoped for:

  • Request and response contracts between the Go services and the SDKs are versioned, so a client can upgrade on its own schedule.
  • Deprecations ship with a working replacement and a two-version window, documented with dates, not vibes.
  • Partner theming and RTL localization live entirely in configuration, so a new brand or language never has to touch the API surface at all.

Partners could upgrade without breaking changes, and in my experience that did more for adoption than any feature we shipped. If I built it again, I'd also add an automatic check in CI that compares the public interface of every pull request with the last release, so a breaking change can't slip through review by accident.

Design your errors like they’re API

The lazy version of an identity SDK throws invalidResponse and lets five bank teams open five identical tickets. We treated errors as carefully as the happy path. Every error answers three questions: whose fault is it, can it be retried, and what should the user see?

public enum BankIDError: Error, Sendable {
    /// Recoverable by the user, message included and localized.
    case userRecoverable(UserRecoverableError)
    /// The integration is wrong. Fails loudly in debug, includes a fix hint.
    case integration(IntegrationError)
    /// The platform said no (camera permission denied, liveness unsupported on this device).
    case capability(CapabilityError)
    /// Transient. Safe to retry with the included policy.
    case transient(retryAfter: Duration)
    /// The session is no longer valid. Only exit: re-authenticate.
    case sessionInvalidated(reason: InvalidationReason)
}

The one that saves the most time is integration: misuse fails immediately and explains itself (“configure was called twice”, “startAuthentication called before configure”). Most SDK support work is other people debugging your silence, so we chose to be loud.

The integration is the product

The real test of an SDK is the afternoon a stranger spends integrating it. Everything that makes that afternoon shorter is worth doing: a sample app that runs every flow, test identities that fail on purpose so teams can practice the unhappy paths, and documentation whose code actually compiles. A lot of my time on BankID went into debugging integrations with partner teams, and almost every one of those sessions pointed at something the docs or the API could have made clearer.

An SDK ships its assumptions. Every implicit expectation about threading, state, or timing becomes an integration bug in someone else’s codebase.

What five banks taught me

One consumer teaches you very little about your API, because you end up bending it around their habits and calling that design. With fifty, you can't talk to any of them. Five turned out to be a good number: enough different opinions to remove everything specific to one bank, and few enough that I knew the engineers on every partner team. The API that made it through five security reviews, five brands and full parity with a separate Android team is the simplest one I've shipped. I don't think that's a coincidence.