summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/methods/startAssertion.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/browser/src/methods/startAssertion.ts')
-rw-r--r--packages/browser/src/methods/startAssertion.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/packages/browser/src/methods/startAssertion.ts b/packages/browser/src/methods/startAssertion.ts
index 603c6fb..37a7915 100644
--- a/packages/browser/src/methods/startAssertion.ts
+++ b/packages/browser/src/methods/startAssertion.ts
@@ -3,6 +3,7 @@ import {
AuthenticatorAssertionResponseJSON,
AssertionCredential,
} from '@webauthntine/typescript-types';
+import base64js from 'base64-js';
import toUint8Array from '../helpers/toUint8Array';
import toBase64String from '../helpers/toBase64String';
@@ -24,10 +25,15 @@ export default async function startAssertion(
const publicKey: PublicKeyCredentialRequestOptions = {
...requestOptionsJSON.publicKey,
challenge: toUint8Array(requestOptionsJSON.publicKey.challenge),
- allowCredentials: requestOptionsJSON.publicKey.allowCredentials.map((cred) => ({
- ...cred,
- id: toUint8Array(cred.id),
- }))
+ allowCredentials: requestOptionsJSON.publicKey.allowCredentials.map((cred) => {
+ // Make sure the credential ID length is a multiple of 4
+ let id = cred.id.padEnd(cred.id.length + (cred.id.length % 4), '=');
+
+ return {
+ ...cred,
+ id: base64js.toByteArray(id),
+ };
+ })
};
// Wait for the user to complete assertion