Skip to content

Commit 07f9c20

Browse files
authored
Convert PublicKeyCredentialRequestOptions.timeout to milliseconds (#26)
* Convert PublicKeyCredentialRequestOptions.timeout to milliseconds. * Add reference to w3.org specification
1 parent c2f970e commit 07f9c20

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

Sources/WebAuthn/Ceremonies/Authentication/PublicKeyCredentialRequestOptions.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import Foundation
1818
public struct PublicKeyCredentialRequestOptions: Codable {
1919
/// A challenge that the authenticator signs, along with other data, when producing an authentication assertion
2020
public let challenge: EncodedBase64
21-
/// A `TimeInterval`, that the Relying Party is willing to wait for the call to complete. The value is treated
21+
/// The number of milliseconds that the Relying Party is willing to wait for the call to complete. The value is treated
2222
/// as a hint, and may be overridden by the client.
23-
public let timeout: TimeInterval?
23+
/// See https://www.w3.org/TR/webauthn-2/#dictionary-assertion-options
24+
public let timeout: UInt32?
2425
/// The Relying Party ID.
2526
public let rpId: String?
2627
/// Optionally used by the client to find authenticators eligible for this authentication ceremony.

Sources/WebAuthn/WebAuthnManager.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,13 @@ public struct WebAuthnManager {
146146
userVerification: UserVerificationRequirement = .preferred
147147
) throws -> PublicKeyCredentialRequestOptions {
148148
let challenge = challenge ?? challengeGenerator.generate().base64EncodedString()
149+
var timeoutInMilliseconds: UInt32? = nil
150+
if let timeout {
151+
timeoutInMilliseconds = UInt32(timeout * 1000)
152+
}
149153
return PublicKeyCredentialRequestOptions(
150154
challenge: challenge,
151-
timeout: timeout,
155+
timeout: timeoutInMilliseconds,
152156
rpId: config.relyingPartyID,
153157
allowCredentials: allowCredentials,
154158
userVerification: userVerification

Tests/WebAuthnTests/WebAuthnManagerAuthenticationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class WebAuthnManagerAuthenticationTests: XCTestCase {
4343
)
4444

4545
XCTAssertEqual(options.challenge, challenge.base64EncodedString())
46-
XCTAssertEqual(options.timeout, 1234)
46+
XCTAssertEqual(options.timeout, 1234000) // timeout converted to milliseconds
4747
XCTAssertEqual(options.rpId, relyingPartyID)
4848
XCTAssertEqual(options.allowCredentials, allowCredentials)
4949
XCTAssertEqual(options.userVerification, .preferred)

Tests/WebAuthnTests/WebAuthnManagerIntegrationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ final class WebAuthnManagerIntegrationTests: XCTestCase {
108108
)
109109

110110
XCTAssertEqual(authenticationOptions.rpId, config.relyingPartyID)
111-
XCTAssertEqual(authenticationOptions.timeout, authenticationTimeout)
111+
XCTAssertEqual(authenticationOptions.timeout, UInt32(authenticationTimeout * 1000)) // timeout is in milliseconds
112112
XCTAssertEqual(authenticationOptions.challenge, mockChallenge.base64EncodedString())
113113
XCTAssertEqual(authenticationOptions.userVerification, userVerification)
114114
XCTAssertEqual(authenticationOptions.allowCredentials, rememberedCredentials)

0 commit comments

Comments
 (0)