Skip to content

Commit 3e77b10

Browse files
Added guiding documentation to the new public initializers
Closes #74
1 parent d52e940 commit 3e77b10

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

Sources/WebAuthn/Ceremonies/Authentication/PublicKeyCredentialRequestOptions.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Foundation
1919
///
2020
/// - SeeAlso: https://www.w3.org/TR/webauthn-2/#dictionary-assertion-options
2121
public struct PublicKeyCredentialRequestOptions: Sendable {
22-
/// A challenge that the authenticator signs, along with other data, when producing an authentication assertion
22+
/// A challenge that the authenticator signs, along with other data, when producing an authentication assertion.
2323
///
2424
/// When encoding using `Encodable` this is encoded as base64url.
2525
public var challenge: [UInt8]
@@ -45,6 +45,16 @@ public struct PublicKeyCredentialRequestOptions: Sendable {
4545

4646
// let extensions: [String: Any]
4747

48+
/// Initialize a credential request options dictionary directly.
49+
///
50+
/// - Warning: Manually initializing options dictionaries can easily lead to insecure implementations of the WebAuthn protocol. Whenever possible, create an options dictionary using ``WebAuthnManager/beginAuthentication(timeout:allowCredentials:userVerification:)`` instead.
51+
///
52+
/// - Parameters:
53+
/// - challenge: A challenge that the authenticator signs, along with other data, when producing an authentication assertion.
54+
/// - timeout: A time, in seconds, that the caller is willing to wait for the call to complete. This is treated as a hint, and may be overridden by the client.
55+
/// - relyingPartyID: The ID of the Relying Party making the request.
56+
/// - allowCredentials: Optionally used by the client to find authenticators eligible for this authentication ceremony.
57+
/// - userVerification: Specifies whether the user should be verified during the authentication ceremony.
4858
public init(
4959
challenge: [UInt8],
5060
timeout: Duration?,

Sources/WebAuthn/Ceremonies/Registration/PublicKeyCredentialCreationOptions.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,34 @@ public struct PublicKeyCredentialCreationOptions: Sendable {
2727
/// encoding using `Encodable`, the challenge is base64url encoded.
2828
public let challenge: [UInt8]
2929

30-
/// Contains names and an identifier for the user account performing the registration
30+
/// Contains names and an identifier for the user account performing the registration.
3131
public var user: PublicKeyCredentialUserEntity
3232

33-
/// Contains a name and an identifier for the Relying Party responsible for the request
33+
/// Contains a name and an identifier for the Relying Party responsible for the request.
3434
public var relyingParty: PublicKeyCredentialRelyingPartyEntity
3535

36-
/// A list of key types and signature algorithms the Relying Party supports. Ordered from most preferred to least
37-
/// preferred.
36+
/// A list of key types and signature algorithms the Relying Party supports. Ordered from most preferred to least preferred.
3837
public var publicKeyCredentialParameters: [PublicKeyCredentialParameters]
3938

40-
/// A time, in seconds, that the caller is willing to wait for the call to complete. This is treated as a
41-
/// hint, and may be overridden by the client.
39+
/// A time, in seconds, that the caller is willing to wait for the call to complete. This is treated as a hint, and may be overridden by the client.
4240
///
4341
/// - Note: When encoded, this value is represented in milleseconds as a ``UInt32``.
4442
public var timeout: Duration?
4543

46-
/// Sets the Relying Party's preference for attestation conveyance. At the time of writing only `none` is
47-
/// supported.
44+
/// Sets the Relying Party's preference for attestation conveyance. At the time of writing only ``AttestationConveyancePreference/none`` is supported.
4845
public var attestation: AttestationConveyancePreference
4946

47+
/// Initialize a credential creation options dictionary directly.
48+
///
49+
/// - Warning: Manually initializing options dictionaries can easily lead to insecure implementations of the WebAuthn protocol. Whenever possible, create an options dictionary using ``WebAuthnManager/beginRegistration(user:timeout:attestation:publicKeyCredentialParameters:)`` instead.
50+
///
51+
/// - Parameters:
52+
/// - challenge: A byte array randomly generated by the Relying Party. Should be at least 16 bytes long to ensure sufficient entropy.
53+
/// - user: Contains names and an identifier for the user account performing the registration.
54+
/// - relyingParty: Contains a name and an identifier for the Relying Party responsible for the request.
55+
/// - publicKeyCredentialParameters: A list of key types and signature algorithms the Relying Party supports. Ordered from most preferred to least preferred.
56+
/// - timeout: A time, in seconds, that the caller is willing to wait for the call to complete. This is treated as a hint, and may be overridden by the client.
57+
/// - attestation: Sets the Relying Party's preference for attestation conveyance. At the time of writing only `none` is supported.
5058
public init(
5159
challenge: [UInt8],
5260
user: PublicKeyCredentialUserEntity,

Sources/WebAuthn/WebAuthnManager.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public struct WebAuthnManager: Sendable {
4646

4747
/// Generate a new set of registration data to be sent to the client.
4848
///
49-
/// This method will use the Relying Party information from the WebAuthnManager's configuration to create ``PublicKeyCredentialCreationOptions``
49+
/// This method will use the Relying Party information from the WebAuthnManager's configuration to create a ready-to-consume ``PublicKeyCredentialCreationOptions`` on the client.
50+
///
51+
/// - Important: You must store the ``PublicKeyCredentialCreationOptions/challenge`` value returned by this method and validate against it during the ``finishRegistration(challenge:credentialCreationData:requireUserVerification:supportedPublicKeyAlgorithms:pemRootCertificatesByFormat:confirmCredentialIDNotRegisteredYet:)`` phase of registration.
52+
///
5053
/// - Parameters:
5154
/// - user: The user to register.
5255
/// - timeout: How long the browser should give the user to choose an authenticator. This value
@@ -126,7 +129,9 @@ public struct WebAuthnManager: Sendable {
126129
)
127130
}
128131

129-
/// Generate options for retrieving a credential via navigator.credentials.get()
132+
/// Generate options for retrieving a credential via `navigator.credentials.get()`.
133+
///
134+
/// - Important: You must store the ``PublicKeyCredentialRequestOptions/challenge`` value returned by this method and validate against it during the ``finishAuthentication(credential:expectedChallenge:credentialPublicKey:credentialCurrentSignCount:requireUserVerification:)`` phase of authentication.
130135
///
131136
/// - Parameters:
132137
/// - timeout: How long the browser should give the user to choose an authenticator. This value

0 commit comments

Comments
 (0)