https://github.com/brokenhandsio/swift-webauthn
A Swift library for implementing the WebAuthn spec
https://github.com/brokenhandsio/swift-webauthn
authentication passkeys swift swift-server webauthn
Last synced: 6 months ago
JSON representation
A Swift library for implementing the WebAuthn spec
- Host: GitHub
- URL: https://github.com/brokenhandsio/swift-webauthn
- Owner: brokenhandsio
- License: apache-2.0
- Created: 2022-07-20T14:43:58.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-10-14T13:49:13.000Z (8 months ago)
- Last Synced: 2025-10-21T09:59:24.934Z (7 months ago)
- Topics: authentication, passkeys, swift, swift-server, webauthn
- Language: Swift
- Homepage: https://swiftpackageindex.com/swift-server/swift-webauthn/main/documentation/webauthn
- Size: 2.67 MB
- Stars: 154
- Watchers: 17
- Forks: 32
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Notice: NOTICE.txt
Awesome Lists containing this project
README
# swift-webauthn
This package provides a Swift implementation of the [WebAuthn API](https://w3c.github.io/webauthn) 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`:
```swift
.package(url: "https://github.com/swift-server/swift-webauthn.git", from: "1.0.0-alpha.2")
```
and `WebAuthn` dependency to your target:
```swift
.target(name: "MyApp", dependencies: [.product(name: "WebAuthn", package: "swift-webauthn")])
```
### Setup
Configure your Relying Party with a `WebAuthnManager` instance:
```swift
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:
```bash
% 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](https://github.com/duo-labs/py_webauthn) and [go-webauthn](https://github.com/go-webauthn/webauthn).
## Links
- [WebAuthn.io](https://webauthn.io/)
- [WebAuthn guide](https://webauthn.guide/)
- [WebAuthn Spec](https://w3c.github.io/webauthn/)
- [CBOR.me](https://cbor.me/)