diff options
author | Matthew Miller <matthew@millerti.me> | 2020-06-01 16:16:13 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-06-01 16:16:13 -0700 |
commit | db28323378648782d92f6552d478a4132d58dcdc (patch) | |
tree | 8e53582b16315393a95bb78f6ddeda680ea48c4b /packages/browser/src/methods/startAssertion.ts | |
parent | 2e31764344df57ec2a9176a74279a459f82729b4 (diff) |
Refactor browser methods to return near-raw resp.
Diffstat (limited to 'packages/browser/src/methods/startAssertion.ts')
-rw-r--r-- | packages/browser/src/methods/startAssertion.ts | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/packages/browser/src/methods/startAssertion.ts b/packages/browser/src/methods/startAssertion.ts index 093cf30..1590634 100644 --- a/packages/browser/src/methods/startAssertion.ts +++ b/packages/browser/src/methods/startAssertion.ts @@ -1,7 +1,7 @@ import { PublicKeyCredentialRequestOptionsJSON, - AuthenticatorAssertionResponseJSON, AssertionCredential, + AssertionCredentialJSON, } from '@simplewebauthn/typescript-types'; import toUint8Array from '../helpers/toUint8Array'; @@ -16,7 +16,7 @@ import toPublicKeyCredentialDescriptor from '../helpers/toPublicKeyCredentialDes */ export default async function startAssertion( requestOptionsJSON: PublicKeyCredentialRequestOptionsJSON, -): Promise<AuthenticatorAssertionResponseJSON> { +): Promise<AssertionCredentialJSON> { if (!supportsWebauthn()) { throw new Error('WebAuthn is not supported in this browser'); } @@ -31,25 +31,29 @@ export default async function startAssertion( }; // Wait for the user to complete assertion - const credential = await navigator.credentials.get({ publicKey }); + const credential = await navigator.credentials.get({ publicKey }) as AssertionCredential; if (!credential) { throw new Error('Assertion was not completed'); } - const { response } = credential as AssertionCredential; + const { rawId, response } = credential; - let base64UserHandle = undefined; + let userHandle = undefined; if (response.userHandle) { - base64UserHandle = toBase64String(response.userHandle); + userHandle = toBase64String(response.userHandle); } // 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), - base64UserHandle, + ...credential, + rawId: toBase64String(rawId), + response: { + ...response, + authenticatorData: toBase64String(response.authenticatorData), + clientDataJSON: toBase64String(response.clientDataJSON), + signature: toBase64String(response.signature), + userHandle, + }, }; } |