You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -49,25 +49,78 @@ interface with a webpage that will handle calling the WebAuthn API:
49
49
50
50
#### Setup
51
51
52
+
Configure your backend with a `WebAuthnManager` instance:
53
+
54
+
```swift
55
+
app.webAuthn=WebAuthnManager(
56
+
config: WebAuthnConfig(
57
+
relyingPartyDisplayName: "My Fancy Web App",
58
+
relyingPartyID: "example.com",
59
+
relyingPartyOrigin: "https://example.com",
60
+
timeout: 600
61
+
)
62
+
)
63
+
```
52
64
53
65
#### Registration
54
66
55
-
1. A user wants to signup on a website using WebAuthn. The client makes a request to the backend which implements this
56
-
library. On request the backend calls the `beginRegistration(user:)` method and sends the returned
57
-
`PublicKeyCredentialCreationOptions` back to the client.
67
+
Scenario: A user wants to signup on a website using WebAuthn.
68
+
69
+
##### Explanation
70
+
71
+
1. When tapping the "Register" button the client sends a request to
72
+
the backend. The backend responds to this request with a call to `begingRegistration(user:)` which then returns a
73
+
new `PublicKeyCredentialRequestOptions`. This must be send back to the client so it can pass it to
74
+
`navigator.credentials.create()`.
58
75
59
-
2. The client passes the received `PublicKeyCredentialCreationOptions` via the WebAuthn API to
60
-
`navigator.credentials.create()`. This in turn will prompt the user to create a new credential using an
61
-
authenticator of their choice (TouchID, security keys, ...). The response must then be send back to the backend.
76
+
2. Whatever `navigator.credentials.create()` returns will be send back to the backend, parsing it into
77
+
`RegistrationCredential`.
78
+
```swift
79
+
let registrationCredential =try req.content.decode(RegistrationCredential.self)
80
+
```
62
81
63
-
3. On request the backend calls the `finishRegistration(challenge:credentialCreationData:)` method with the previously
64
-
generated challenge and the received authenticator response (from `navigator.credentials.create()`). If
65
-
`finishRegistration` succeeds a new `Credential` object will be returned. This object should be persisted somewhere
66
-
(e.g. a database) and linked to the user from step 1.
82
+
3. Next the backend calls `finishRegistration(challenge:credentialCreationData:)` with the previously
83
+
generated challenge and the received `RegistrationCredential`. If `finishRegistration` succeeds a new `Credential`
84
+
object will be returned. This object contains information about the new credential, including an id and the generated public-key. Persist this data in e.g. a database and link the entry to the user.
85
+
86
+
##### Example implementation
87
+
88
+
```swift
89
+
authSessionRoutes.get("makeCredential") { req -> PublicKeyCredentialCreationOptions in
90
+
let user =try req.auth.require(User.self)
91
+
let options =try req.webAuthn.beginRegistration(user: user)
92
+
req.session.data["challenge"] = options.challenge
93
+
return options
94
+
}
95
+
96
+
authSessionRoutes.post("makeCredential") { req -> HTTPStatus in
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).
0 commit comments