Skip to content

Commit 681eb6f

Browse files
authored
Merge pull request #43 from dimitribouniol/dimitri/configuration
2 parents db38c0e + 651e2ff commit 681eb6f

8 files changed

+30
-31
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ Configure your Relying Party with a `WebAuthnManager` instance:
2525

2626
```swift
2727
let webAuthnManager = WebAuthnManager(
28-
config: WebAuthnConfig(
29-
relyingPartyDisplayName: "My Fancy Web App",
28+
configuration: WebAuthnManager.Configuration(
3029
relyingPartyID: "example.com",
31-
relyingPartyOrigin: "https://example.com",
32-
timeout: 600
30+
relyingPartyName: "My Fancy Web App",
31+
relyingPartyOrigin: "https://example.com"
3332
)
3433
)
3534
```

Sources/WebAuthn/Docs.docc/Example Implementation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Configure your backend with a ``WebAuthnManager`` instance:
3636

3737
```swift
3838
let webAuthnManager = WebAuthnManager(
39-
config: .init(
39+
configuration: .init(
4040
relyingPartyID: "example.com",
4141
relyingPartyName: "My Fancy Web App",
4242
relyingPartyOrigin: "https://example.com"
@@ -160,4 +160,4 @@ authSessionRoutes.post("authenticate") { req -> HTTPStatus in
160160

161161
return .ok
162162
}
163-
```
163+
```

Sources/WebAuthn/Docs.docc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ the corresponding user in a database.
2323
### Essentials
2424

2525
- ``WebAuthnManager``
26-
- ``WebAuthnManager/Config``
26+
- ``WebAuthnManager/Configuration``
2727
- ``PublicKeyCredentialUserEntity``
2828

2929
### Responses

Sources/WebAuthn/WebAuthnManager+Config.swift renamed to Sources/WebAuthn/WebAuthnManager+Configuration.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import Foundation
1616

1717
extension WebAuthnManager {
18-
/// Config represents the WebAuthn configuration.
19-
public struct Config {
18+
/// Configuration represents the WebAuthn configuration.
19+
public struct Configuration {
2020
/// The relying party id is based on the host's domain.
2121
/// It does not include a scheme or port (like the `relyingPartyOrigin`).
2222
/// For example, if the origin is https://login.example.com:1337, then _login.example.com_ or _example.com_ are
@@ -29,7 +29,7 @@ extension WebAuthnManager {
2929
/// The domain, with HTTP protocol (e.g. "https://example.com")
3030
public let relyingPartyOrigin: String
3131

32-
/// Creates a new `WebAuthnConfig` with information about the Relying Party
32+
/// Creates a new ``WebAuthnManager.Configuration`` with information about the Relying Party
3333
/// - Parameters:
3434
/// - relyingPartyID: The relying party id is based on the host's domain. (e.g. _login.example.com_)
3535
/// - relyingPartyName: Name for the Relying Party. Can be any string.

Sources/WebAuthn/WebAuthnManager.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ import Foundation
2828
/// When the client has received the response from the authenticator, pass the response to
2929
/// `finishAuthentication()`.
3030
public struct WebAuthnManager {
31-
private let config: Config
31+
private let configuration: Configuration
3232

3333
private let challengeGenerator: ChallengeGenerator
3434

3535
/// Create a new WebAuthnManager using the given configuration and challenge generator.
3636
///
3737
/// - Parameters:
38-
/// - config: The configuration to use for this manager.
38+
/// - configuration: The configuration to use for this manager.
3939
/// - challengeGenerator: The challenge generator to use for this manager. Defaults to a live generator.
40-
public init(config: Config, challengeGenerator: ChallengeGenerator = .live) {
41-
self.config = config
40+
public init(configuration: Configuration, challengeGenerator: ChallengeGenerator = .live) {
41+
self.configuration = configuration
4242
self.challengeGenerator = challengeGenerator
4343
}
4444

4545
/// Generate a new set of registration data to be sent to the client.
4646
///
47-
/// This method will use the Relying Party information from the WebAuthnManager's config to create ``PublicKeyCredentialCreationOptions``
47+
/// This method will use the Relying Party information from the WebAuthnManager's configuration to create ``PublicKeyCredentialCreationOptions``
4848
/// - Parameters:
4949
/// - user: The user to register.
5050
/// - timeout: How long the browser should give the user to choose an authenticator. This value
@@ -64,7 +64,7 @@ public struct WebAuthnManager {
6464
return PublicKeyCredentialCreationOptions(
6565
challenge: challenge,
6666
user: user,
67-
relyingParty: .init(id: config.relyingPartyID, name: config.relyingPartyName),
67+
relyingParty: .init(id: configuration.relyingPartyID, name: configuration.relyingPartyName),
6868
publicKeyCredentialParameters: publicKeyCredentialParameters,
6969
timeout: timeout,
7070
attestation: attestation
@@ -98,8 +98,8 @@ public struct WebAuthnManager {
9898
let attestedCredentialData = try await parsedData.verify(
9999
storedChallenge: challenge,
100100
verifyUser: requireUserVerification,
101-
relyingPartyID: config.relyingPartyID,
102-
relyingPartyOrigin: config.relyingPartyOrigin,
101+
relyingPartyID: configuration.relyingPartyID,
102+
relyingPartyOrigin: configuration.relyingPartyOrigin,
103103
supportedPublicKeyAlgorithms: supportedPublicKeyAlgorithms,
104104
pemRootCertificatesByFormat: pemRootCertificatesByFormat
105105
)
@@ -143,7 +143,7 @@ public struct WebAuthnManager {
143143
return PublicKeyCredentialRequestOptions(
144144
challenge: challenge,
145145
timeout: timeout,
146-
rpId: config.relyingPartyID,
146+
rpId: configuration.relyingPartyID,
147147
allowCredentials: allowCredentials,
148148
userVerification: userVerification
149149
)
@@ -172,8 +172,8 @@ public struct WebAuthnManager {
172172
let parsedAssertion = try ParsedAuthenticatorAssertionResponse(from: credential.response)
173173
try parsedAssertion.verify(
174174
expectedChallenge: expectedChallenge,
175-
relyingPartyOrigin: config.relyingPartyOrigin,
176-
relyingPartyID: config.relyingPartyID,
175+
relyingPartyOrigin: configuration.relyingPartyOrigin,
176+
relyingPartyID: configuration.relyingPartyID,
177177
requireUserVerification: requireUserVerification,
178178
credentialPublicKey: credentialPublicKey,
179179
credentialCurrentSignCount: credentialCurrentSignCount

Tests/WebAuthnTests/WebAuthnManagerAuthenticationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ final class WebAuthnManagerAuthenticationTests: XCTestCase {
2626
let relyingPartyOrigin = "https://example.com"
2727

2828
override func setUp() {
29-
let config = WebAuthnManager.Config(
29+
let configuration = WebAuthnManager.Configuration(
3030
relyingPartyID: relyingPartyID,
3131
relyingPartyName: relyingPartyName,
3232
relyingPartyOrigin: relyingPartyOrigin
3333
)
34-
webAuthnManager = .init(config: config, challengeGenerator: .mock(generate: challenge))
34+
webAuthnManager = .init(configuration: configuration, challengeGenerator: .mock(generate: challenge))
3535
}
3636

3737
func testBeginAuthentication() async throws {

Tests/WebAuthnTests/WebAuthnManagerIntegrationTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import Crypto
1919
final class WebAuthnManagerIntegrationTests: XCTestCase {
2020
// swiftlint:disable:next function_body_length
2121
func testRegistrationAndAuthenticationSucceeds() async throws {
22-
let config = WebAuthnManager.Config(
22+
let configuration = WebAuthnManager.Configuration(
2323
relyingPartyID: "example.com",
2424
relyingPartyName: "Example RP",
2525
relyingPartyOrigin: "https://example.com"
2626
)
2727

2828
let mockChallenge = [UInt8](repeating: 0, count: 5)
2929
let challengeGenerator = ChallengeGenerator(generate: { mockChallenge })
30-
let webAuthnManager = WebAuthnManager(config: config, challengeGenerator: challengeGenerator)
30+
let webAuthnManager = WebAuthnManager(configuration: configuration, challengeGenerator: challengeGenerator)
3131

3232
// Step 1.: Begin Registration
3333
let mockUser = PublicKeyCredentialUserEntity.mock
@@ -47,8 +47,8 @@ final class WebAuthnManagerIntegrationTests: XCTestCase {
4747
XCTAssertEqual(registrationOptions.user.name, mockUser.name)
4848
XCTAssertEqual(registrationOptions.user.displayName, mockUser.displayName)
4949
XCTAssertEqual(registrationOptions.attestation, attestationPreference)
50-
XCTAssertEqual(registrationOptions.relyingParty.id, config.relyingPartyID)
51-
XCTAssertEqual(registrationOptions.relyingParty.name, config.relyingPartyName)
50+
XCTAssertEqual(registrationOptions.relyingParty.id, configuration.relyingPartyID)
51+
XCTAssertEqual(registrationOptions.relyingParty.name, configuration.relyingPartyName)
5252
XCTAssertEqual(registrationOptions.timeout, timeout)
5353
XCTAssertEqual(registrationOptions.publicKeyCredentialParameters, publicKeyCredentialParameters)
5454

@@ -106,7 +106,7 @@ final class WebAuthnManagerIntegrationTests: XCTestCase {
106106
userVerification: userVerification
107107
)
108108

109-
XCTAssertEqual(authenticationOptions.rpId, config.relyingPartyID)
109+
XCTAssertEqual(authenticationOptions.rpId, configuration.relyingPartyID)
110110
XCTAssertEqual(authenticationOptions.timeout, authenticationTimeout)
111111
XCTAssertEqual(authenticationOptions.challenge, mockChallenge)
112112
XCTAssertEqual(authenticationOptions.userVerification, userVerification)
@@ -115,7 +115,7 @@ final class WebAuthnManagerIntegrationTests: XCTestCase {
115115
// Now send `authenticationOptions` to client, which in turn will send the authenticator's response back to us:
116116
// The following lines reflect what an authenticator normally produces
117117
let authenticatorData = TestAuthDataBuilder().validAuthenticationMock()
118-
.rpIDHash(fromRpID: config.relyingPartyID)
118+
.rpIDHash(fromRpID: configuration.relyingPartyID)
119119
.counter([0, 0, 0, 1]) // we authenticated once now, so authenticator likely increments the sign counter
120120
.build()
121121
.byteArrayRepresentation

Tests/WebAuthnTests/WebAuthnManagerRegistrationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ final class WebAuthnManagerRegistrationTests: XCTestCase {
2626
let relyingPartyOrigin = "https://example.com"
2727

2828
override func setUp() {
29-
let config = WebAuthnManager.Config(
29+
let configuration = WebAuthnManager.Configuration(
3030
relyingPartyID: relyingPartyID,
3131
relyingPartyName: relyingPartyDisplayName,
3232
relyingPartyOrigin: relyingPartyOrigin
3333
)
34-
webAuthnManager = .init(config: config, challengeGenerator: .mock(generate: challenge))
34+
webAuthnManager = .init(configuration: configuration, challengeGenerator: .mock(generate: challenge))
3535
}
3636

3737
// MARK: - beginRegistration()

0 commit comments

Comments
 (0)