12
12
//
13
13
//===----------------------------------------------------------------------===//
14
14
15
- import Crypto
16
15
import Foundation
17
- import Logging
18
- import SwiftCBOR
19
16
20
17
public struct WebAuthnManager {
21
18
private let config : WebAuthnConfig
@@ -28,8 +25,16 @@ public struct WebAuthnManager {
28
25
}
29
26
30
27
/// Generate a new set of registration data to be sent to the client and authenticator.
28
+ ///
29
+ /// - Parameters:
30
+ /// - user: The user to register.
31
+ /// - attestation: The level of attestation to be provided by the authenticator.
32
+ /// - publicKeyCredentialParameters: A list of public key algorithms the Relying Party chooses to restrict
33
+ /// support to. Defaults to all supported algorithms.
34
+ /// - Returns: Registration options ready for the browser.
31
35
public func beginRegistration(
32
36
user: WebAuthnUser ,
37
+ timeout: TimeInterval = 60000 ,
33
38
attestation: AttestationConveyancePreference = . none,
34
39
publicKeyCredentialParameters: [ PublicKeyCredentialParameters ] = PublicKeyCredentialParameters . supported
35
40
) throws -> PublicKeyCredentialCreationOptions {
@@ -47,17 +52,25 @@ public struct WebAuthnManager {
47
52
user: userEntity,
48
53
rp: relyingParty,
49
54
pubKeyCredParams: publicKeyCredentialParameters,
50
- timeout: config . timeout,
55
+ timeout: timeout,
51
56
attestation: attestation
52
57
)
53
58
}
54
59
55
60
/// Take response from authenticator and client and verify credential against the user's credentials and
56
61
/// session data.
62
+ ///
57
63
/// - Parameters:
58
- /// - challenge: The user to verify against the authenticator response. Base64 encoded .
64
+ /// - challenge: The challenge passed to the authenticator within the preceding registration options .
59
65
/// - credentialCreationData: The value returned from `navigator.credentials.create()`
60
66
/// - requireUserVerification: Whether or not to require that the authenticator verified the user.
67
+ /// - supportedPublicKeyAlgorithms: A list of public key algorithms the Relying Party chooses to restrict
68
+ /// support to. Defaults to all supported algorithms.
69
+ /// - pemRootCertificatesByFormat: A list of root certificates used for attestation verification.
70
+ /// If attestation verification is not required (default behavior) this parameter does nothing.
71
+ /// - confirmCredentialIDNotRegisteredYet: For a successful registration ceremony we need to verify that the
72
+ /// `credentialId`, generated by the authenticator, is not yet registered for any user. This is a good place to
73
+ /// handle that.
61
74
/// - Returns: A new `Credential` with information about the authenticator and registration
62
75
public func finishRegistration(
63
76
challenge: EncodedBase64 ,
@@ -97,9 +110,20 @@ public struct WebAuthnManager {
97
110
)
98
111
}
99
112
113
+ /// Generate options for retrieving a credential via navigator.credentials.get()
114
+ ///
115
+ /// - Parameters:
116
+ /// - challenge: Optionally generate a challenge on your own. Defaults to `nil` which will let the library
117
+ /// generate it.
118
+ /// - timeout: How long in milliseconds the browser should give the user to choose an authenticator. This value
119
+ /// is a *hint* and may be ignored by the browser.
120
+ /// - allowCredentials: A list of credentials registered to the user.
121
+ /// - userVerification: The Relying Party's preference for the authenticator's enforcement of the
122
+ /// "user verified" flag.
123
+ /// - Returns: Authentication options ready for the browser.
100
124
public func beginAuthentication(
101
125
challenge: EncodedBase64 ? = nil ,
102
- timeout: TimeInterval ? ,
126
+ timeout: TimeInterval ? = 60000 ,
103
127
allowCredentials: [ PublicKeyCredentialDescriptor ] ? = nil ,
104
128
userVerification: UserVerificationRequirement = . preferred
105
129
) throws -> PublicKeyCredentialRequestOptions {
@@ -113,6 +137,16 @@ public struct WebAuthnManager {
113
137
)
114
138
}
115
139
140
+ /// Verify a response from navigator.credentials.get()
141
+ ///
142
+ /// - Parameters:
143
+ /// - credential: The value returned from `navigator.credentials.get()`.
144
+ /// - expectedChallenge: The challenge passed to the authenticator within the preceding authentication options.
145
+ /// - credentialPublicKey: The public key for the credential's ID as provided in a preceding authenticator
146
+ /// registration ceremony.
147
+ /// - credentialCurrentSignCount: The current known number of times the authenticator was used.
148
+ /// - requireUserVerification: Whether or not to require that the authenticator verified the user.
149
+ /// - Returns: Information about the authenticator
116
150
public func finishAuthentication(
117
151
credential: AuthenticationCredential ,
118
152
// clientExtensionResults: ,
0 commit comments