Contents

brokenhandsio/swift-webauthn

A Swift library for implementing the WebAuthn spec

Getting Started

Adding the dependency

Add the following entry in your Package.swift to start using WebAuthn:

.package(url: "https://github.com/swift-server/swift-webauthn.git", from: "1.0.0-alpha.2")

and WebAuthn dependency to your target:

.target(name: "MyApp", dependencies: [.product(name: "WebAuthn", package: "swift-webauthn")])

Setup

Configure your Relying Party with a WebAuthnManager instance:

let webAuthnManager = WebAuthnManager(
    configuration: WebAuthnManager.Configuration(
        relyingPartyID: "example.com",
        relyingPartyName: "My Fancy Web App",
        relyingPartyOrigin: "https://example.com"
    )
)

Registration

For a registration ceremony use the following two methods:

  • WebAuthnManager.beginRegistration()
  • WebAuthnManager.finishRegistration()

Authentication

For an authentication ceremony use the following two methods:

  • WebAuthnManager.beginAuthentication()
  • WebAuthnManager.finishAuthentication()

Contributing

If you add any new files, please run the following command at the root of the repo to identify any missing license headers:

% PROJECTNAME="Swift WebAuthn" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/check-license-header.sh)"

Credits

Swift WebAuthn is heavily inspired by existing WebAuthn libraries like py_webauthn and go-webauthn.

Package Metadata

Repository: brokenhandsio/swift-webauthn

Homepage: https://swiftpackageindex.com/swift-server/swift-webauthn/main/documentation/webauthn

Stars: 172

Forks: 37

Open issues: 15

Default branch: main

Primary language: swift

License: Apache-2.0

Topics: authentication, passkeys, swift, swift-server, webauthn

README: README.md