diff options
author | Matthew Miller <matthew@millerti.me> | 2022-02-01 22:44:13 -0800 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2022-02-01 22:44:13 -0800 |
commit | 541fa560c10a9f18dbe910da46b507eee1564d93 (patch) | |
tree | 9d986b1cd14d4afcfccab1d454251314d204de84 /packages/server/src/authentication/verifyAuthenticationResponse.ts | |
parent | 6f532850088cd66215b12766cf6c755e750fafd6 (diff) |
Support custom challenge verifier during auth
Diffstat (limited to 'packages/server/src/authentication/verifyAuthenticationResponse.ts')
-rw-r--r-- | packages/server/src/authentication/verifyAuthenticationResponse.ts | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/packages/server/src/authentication/verifyAuthenticationResponse.ts b/packages/server/src/authentication/verifyAuthenticationResponse.ts index cd83be3..c1ccc65 100644 --- a/packages/server/src/authentication/verifyAuthenticationResponse.ts +++ b/packages/server/src/authentication/verifyAuthenticationResponse.ts @@ -14,7 +14,7 @@ import isBase64URLString from '../helpers/isBase64URLString'; export type VerifyAuthenticationResponseOpts = { credential: AuthenticationCredentialJSON; - expectedChallenge: string; + expectedChallenge: string | ((challenge: string) => boolean); expectedOrigin: string | string[]; expectedRPID: string | string[]; authenticator: AuthenticatorDevice; @@ -82,7 +82,13 @@ export default function verifyAuthenticationResponse( } // Ensure the device provided the challenge we gave it - if (challenge !== expectedChallenge) { + if (typeof expectedChallenge === 'function') { + if (!expectedChallenge(challenge)) { + throw new Error( + `Custom challenge verifier returned false for registration response challenge "${challenge}"`, + ); + } + } else if (challenge !== expectedChallenge) { throw new Error( `Unexpected authentication response challenge "${challenge}", expected "${expectedChallenge}"`, ); |