Skip to content

Commit f15bc61

Browse files
Added an AuthenticatorAttachment enumeration
1 parent d54c8fb commit f15bc61

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

Sources/WebAuthn/Ceremonies/Authentication/AuthenticationCredential.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public struct AuthenticationCredential {
2929

3030
/// Reports the authenticator attachment modality in effect at the time the navigator.credentials.create() or
3131
/// navigator.credentials.get() methods successfully complete
32-
public let authenticatorAttachment: String?
32+
public let authenticatorAttachment: AuthenticatorAttachment?
3333

3434
/// Value will always be "public-key" (for now)
3535
public let type: String
@@ -42,7 +42,7 @@ extension AuthenticationCredential: Decodable {
4242
id = try container.decode(URLEncodedBase64.self, forKey: .id)
4343
rawID = try container.decodeBytesFromURLEncodedBase64(forKey: .rawID)
4444
response = try container.decode(AuthenticatorAssertionResponse.self, forKey: .response)
45-
authenticatorAttachment = try container.decodeIfPresent(String.self, forKey: .authenticatorAttachment)
45+
authenticatorAttachment = try container.decodeIfPresent(AuthenticatorAttachment.self, forKey: .authenticatorAttachment)
4646
type = try container.decode(String.self, forKey: .type)
4747
}
4848

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the WebAuthn Swift open source project
4+
//
5+
// Copyright (c) 2024 the WebAuthn Swift project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of WebAuthn Swift project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
/// An authenticators' attachment modalities.
16+
///
17+
/// Relying Parties use this to express a preferred authenticator attachment modality when registering a credential, and clients use this to report the authenticator attachment modality used to complete a registration or authentication ceremony.
18+
/// - SeeAlso: [WebAuthn Level 3 Editor's Draft §5.4.5. Authenticator Attachment Enumeration (enum AuthenticatorAttachment)](https://w3c.github.io/webauthn/#enum-attachment)
19+
/// - SeeAlso: [WebAuthn Level 3 Editor's Draft §6.2.1. Authenticator Attachment Modality](https://w3c.github.io/webauthn/#sctn-authenticator-attachment-modality)
20+
///
21+
public struct AuthenticatorAttachment: UnreferencedStringEnumeration {
22+
public var rawValue: String
23+
public init(_ rawValue: String) {
24+
self.rawValue = rawValue
25+
}
26+
27+
/// A platform authenticator is attached using a client device-specific transport, called platform attachment, and is usually not removable from the client device. A public key credential bound to a platform authenticator is called a platform credential.
28+
/// - SeeAlso: [WebAuthn Level 3 Editor's Draft §6.2.1. Authenticator Attachment Modality](https://w3c.github.io/webauthn/#platform-attachment)
29+
public static let platform: Self = "platform"
30+
31+
/// A roaming authenticator is attached using cross-platform transports, called cross-platform attachment. Authenticators of this class are removable from, and can "roam" between, client devices. A public key credential bound to a roaming authenticator is called a roaming credential.
32+
/// - SeeAlso: [WebAuthn Level 3 Editor's Draft §6.2.1. Authenticator Attachment Modality](https://w3c.github.io/webauthn/#cross-platform-attachment)
33+
public static let crossPlatform: Self = "cross-platform"
34+
}

Tests/WebAuthnTests/WebAuthnManagerAuthenticationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ final class WebAuthnManagerAuthenticationTests: XCTestCase {
165165
signature: [UInt8] = TestECCKeyPair.signature,
166166
userHandle: [UInt8]? = "36323638424436452d303831452d344331312d413743332d334444304146333345433134".hexadecimal!,
167167
attestationObject: [UInt8]? = nil,
168-
authenticatorAttachment: String? = "platform",
168+
authenticatorAttachment: AuthenticatorAttachment? = .platform,
169169
type: String = "public-key",
170170
expectedChallenge: [UInt8] = TestConstants.mockChallenge,
171171
credentialPublicKey: [UInt8] = TestCredentialPublicKeyBuilder().validMock().buildAsByteArray(),

Tests/WebAuthnTests/WebAuthnManagerIntegrationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ final class WebAuthnManagerIntegrationTests: XCTestCase {
143143
userHandle: mockUser.id,
144144
attestationObject: nil
145145
),
146-
authenticatorAttachment: "platform",
146+
authenticatorAttachment: .platform,
147147
type: "public-key"
148148
)
149149

0 commit comments

Comments
 (0)