diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-22 18:22:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 18:22:21 -0700 |
commit | d6dc6e5bfc588036db2c1b2212b8f8bc74b1c0f5 (patch) | |
tree | b58d6593de62689f0a13a8ea932e5892aefb29de /packages/browser/src/methods/startAssertion.ts | |
parent | efe856ed238e7a2be8d847c94ba8e0155b17ce9c (diff) | |
parent | 2548e4fd6a5e3d82b2f1b348eec442bd318e4872 (diff) |
Merge pull request #2 from MasterKale/feature/example-site
feature/example-site
Diffstat (limited to 'packages/browser/src/methods/startAssertion.ts')
-rw-r--r-- | packages/browser/src/methods/startAssertion.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/packages/browser/src/methods/startAssertion.ts b/packages/browser/src/methods/startAssertion.ts index 603c6fb..8e411ec 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 @@ -46,6 +52,7 @@ export default async function startAssertion( // Convert values to base64 to make it easier to send back to the server return { + base64CredentialID: credential.id, base64AuthenticatorData: toBase64String(response.authenticatorData), base64ClientDataJSON: toBase64String(response.clientDataJSON), base64Signature: toBase64String(response.signature), |