MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.62k stars 137 forks source link

Allow expectedChallenge to return a Promise #432

Closed jordanbtucker closed 1 year ago

jordanbtucker commented 1 year ago

This PR allows verifyAuthenticationResponse and verifyRegistrationResponse to accept expectedChallenge properties of their options parameter to be Promise returning functions. This allows code like this:

async function customAsyncVerification(challenge: string): Promise<boolean> {
   ...
}

const isVerified = await verifyAuthenticationResponse({
  ...
  expectedChallenge: customAsyncVerification,
  ...
});

Three tests per verification function have been added:

  1. Checks for Promises that resolve with true.
  2. Checks for Promises that resolve with false.
  3. Checks for Promises that reject.

Fixes #431