-
-
Notifications
You must be signed in to change notification settings - Fork 34
Add support for optional AuthenticatorSelection #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dimitribouniol
merged 5 commits into
brokenhandsio:main
from
edgewoodsailing:authenticatorSelection-upstream
Nov 25, 2025
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ccb6de2
Add authenticator selection criteria to registration options
samalone 9e0fe96
Refactor authenticator selection handling in registration process
samalone 91e1acf
Enhance AuthenticatorSelection struct for improved decoding and encoding
samalone 12a09aa
Refactor AuthenticatorSelection struct to streamline Codable conformance
samalone 31ce9fd
Merge branch 'main' into authenticatorSelection-upstream
samalone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
Sources/WebAuthn/Ceremonies/Registration/AuthenticatorSelection.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift WebAuthn open source project | ||
| // | ||
| // Copyright (c) 2022 the Swift WebAuthn project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import Foundation | ||
|
|
||
| /// A dictionary describing the Relying Party's requirements regarding authenticator attributes. | ||
| /// | ||
| /// - SeeAlso: [WebAuthn Level 3 Working Draft §5.4.4. Authenticator Selection Criteria](https://www.w3.org/TR/webauthn-3/#dictionary-authenticatorSelection) | ||
| public struct AuthenticatorSelection: Codable, Sendable, Hashable { | ||
| /// If present, indicates the Relying Party's preference for authenticator attachment. | ||
| /// - SeeAlso: [WebAuthn Level 3 Working Draft §5.4.4. Authenticator Selection Criteria](https://www.w3.org/TR/webauthn-3/#dom-authenticatorselectioncriteria-authenticatorattachment) | ||
| public var authenticatorAttachment: AuthenticatorAttachment? | ||
|
|
||
| /// Describes the Relying Party's requirements regarding whether the authenticator should create a client-side-resident public key credential source. | ||
| /// - SeeAlso: [WebAuthn Level 3 Working Draft §5.4.4. Authenticator Selection Criteria](https://www.w3.org/TR/webauthn-3/#dom-authenticatorselectioncriteria-residentkey) | ||
| public var residentKey: ResidentKeyRequirement? | ||
samalone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Describes the Relying Party's requirements regarding user verification. | ||
| /// - SeeAlso: [WebAuthn Level 3 Working Draft §5.4.4. Authenticator Selection Criteria](https://www.w3.org/TR/webauthn-3/#dom-authenticatorselectioncriteria-userverification) | ||
| public var userVerification: UserVerificationRequirement? | ||
|
|
||
| public init( | ||
| authenticatorAttachment: AuthenticatorAttachment? = nil, | ||
| residentKey: ResidentKeyRequirement? = nil, | ||
| userVerification: UserVerificationRequirement? = nil | ||
| ) { | ||
| self.authenticatorAttachment = authenticatorAttachment | ||
| self.residentKey = residentKey | ||
| self.userVerification = userVerification | ||
| } | ||
| } | ||
|
|
||
| extension AuthenticatorSelection { | ||
samalone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public init(from decoder: any Decoder) throws { | ||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
|
||
| self.authenticatorAttachment = try container.decodeIfPresent( | ||
| AuthenticatorAttachment.self, forKey: .authenticatorAttachment) | ||
| self.residentKey = try container.decodeIfPresent( | ||
| ResidentKeyRequirement.self, forKey: .residentKey) | ||
| self.userVerification = try container.decodeIfPresent( | ||
| UserVerificationRequirement.self, forKey: .userVerification) | ||
|
|
||
| // requireResidentKey is ignored during decoding as it's derived from residentKey | ||
| // It's only included in encoding for backwards compatibility with WebAuthn Level 1 | ||
| } | ||
|
|
||
| public func encode(to encoder: any Encoder) throws { | ||
| var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
|
||
| try container.encodeIfPresent(authenticatorAttachment, forKey: .authenticatorAttachment) | ||
| try container.encodeIfPresent(residentKey, forKey: .residentKey) | ||
| try container.encodeIfPresent(userVerification, forKey: .userVerification) | ||
|
|
||
| // requireResidentKey is included for backwards compatibility with WebAuthn Level 1 | ||
| // It should be true if and only if residentKey is set to .required | ||
| let requireResidentKey = residentKey == .required | ||
| try container.encode(requireResidentKey, forKey: .requireResidentKey) | ||
| } | ||
|
|
||
| private enum CodingKeys: String, CodingKey { | ||
| case authenticatorAttachment | ||
| case residentKey | ||
| case userVerification | ||
| case requireResidentKey | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Sources/WebAuthn/Ceremonies/Registration/ResidentKeyRequirement.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift WebAuthn open source project | ||
| // | ||
| // Copyright (c) 2022 the Swift WebAuthn project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import Foundation | ||
|
|
||
| /// The Relying Party's requirements regarding whether the authenticator should create a client-side-resident public key credential source. | ||
| /// | ||
| /// - SeeAlso: [WebAuthn Level 3 Working Draft §5.4.6. Resident Key Requirement Enumeration](https://www.w3.org/TR/webauthn-3/#enum-residentKeyRequirement) | ||
| public struct ResidentKeyRequirement: UnreferencedStringEnumeration, Sendable { | ||
| public var rawValue: String | ||
|
|
||
| public init(_ rawValue: String) { | ||
| self.rawValue = rawValue | ||
| } | ||
|
|
||
| /// This value indicates the Relying Party requires a client-side-resident credential (i.e., a discoverable credential). | ||
| /// | ||
| /// If the authenticator cannot create a client-side-resident credential, it will return an error. | ||
| /// - SeeAlso: [WebAuthn Level 3 Working Draft §5.4.6. Resident Key Requirement Enumeration](https://www.w3.org/TR/webauthn-3/#dom-residentkeyrequirement-required) | ||
| public static let required: Self = "required" | ||
|
|
||
| /// This value indicates the Relying Party strongly prefers a client-side-resident credential, but will accept a server-side credential. | ||
| /// - SeeAlso: [WebAuthn Level 3 Working Draft §5.4.6. Resident Key Requirement Enumeration](https://www.w3.org/TR/webauthn-3/#dom-residentkeyrequirement-preferred) | ||
| public static let preferred: Self = "preferred" | ||
samalone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// This value indicates the Relying Party strongly prefers a server-side credential, but will accept a client-side-resident credential. | ||
| /// - SeeAlso: [WebAuthn Level 3 Working Draft §5.4.6. Resident Key Requirement Enumeration](https://www.w3.org/TR/webauthn-3/#dom-residentkeyrequirement-discouraged) | ||
| public static let discouraged: Self = "discouraged" | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.