swift-server / swift-webauthn

A Swift library for implementing the WebAuthn spec
https://swiftpackageindex.com/swift-server/webauthn-swift/main/documentation/webauthn
Apache License 2.0
127 stars 25 forks source link
authentication passkeys swift swift-server webauthn

swift-webauthn

This package provides a Swift implementation of the WebAuthn API focused on making it easy to leverage the power of WebAuthn to support Passkeys and security keys.

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:

Authentication

For an authentication ceremony use the following two methods:

Credits

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

Links