diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-25 23:57:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-25 23:57:59 -0700 |
commit | 5793fe2f0214c35038dee0f9bf37e7894805ee07 (patch) | |
tree | db2bd52ac2cb1cd55442bf9b320b4e0e36f4d8f4 /packages/browser/src/methods | |
parent | d0205b9a4f2b4e304447e8072e4384f52dcc0c51 (diff) | |
parent | ddd8889dd0b7249ed24736c0e4e89e0bd041d9c6 (diff) |
Merge pull request #11 from MasterKale/feature/exclude-credentials-attestation
feature/exclude-credentials-attestation
Diffstat (limited to 'packages/browser/src/methods')
-rw-r--r-- | packages/browser/src/methods/startAssertion.ts | 15 | ||||
-rw-r--r-- | packages/browser/src/methods/startAttestation.test.ts | 10 | ||||
-rw-r--r-- | packages/browser/src/methods/startAttestation.ts | 4 |
3 files changed, 18 insertions, 11 deletions
diff --git a/packages/browser/src/methods/startAssertion.ts b/packages/browser/src/methods/startAssertion.ts index f504f19..826763a 100644 --- a/packages/browser/src/methods/startAssertion.ts +++ b/packages/browser/src/methods/startAssertion.ts @@ -3,11 +3,11 @@ import { AuthenticatorAssertionResponseJSON, AssertionCredential, } from '@webauthntine/typescript-types'; -import base64js from 'base64-js'; import toUint8Array from '../helpers/toUint8Array'; import toBase64String from '../helpers/toBase64String'; import supportsWebauthn from '../helpers/supportsWebauthn'; +import toPublicKeyCredentialDescriptor from '../helpers/toPublicKeyCredentialDescriptor'; /** * Begin authenticator "login" via WebAuthn assertion @@ -25,16 +25,9 @@ export default async function startAssertion( const publicKey: PublicKeyCredentialRequestOptions = { ...requestOptionsJSON.publicKey, challenge: toUint8Array(requestOptionsJSON.publicKey.challenge), - allowCredentials: requestOptionsJSON.publicKey.allowCredentials.map(cred => { - // Make sure the credential ID length is a multiple of 4 - const padLength = 4 - (cred.id.length % 4); - const id = cred.id.padEnd(cred.id.length + padLength, '='); - - return { - ...cred, - id: base64js.toByteArray(id), - }; - }), + allowCredentials: requestOptionsJSON.publicKey.allowCredentials.map( + toPublicKeyCredentialDescriptor, + ), }; // Wait for the user to complete assertion diff --git a/packages/browser/src/methods/startAttestation.test.ts b/packages/browser/src/methods/startAttestation.test.ts index 539ffe5..faeca8b 100644 --- a/packages/browser/src/methods/startAttestation.test.ts +++ b/packages/browser/src/methods/startAttestation.test.ts @@ -38,6 +38,11 @@ const goodOpts1: PublicKeyCredentialCreationOptionsJSON = { name: 'username', }, timeout: 1, + excludeCredentials: [{ + id: 'authIdentifier', + type: 'public-key', + transports: ['internal'], + }], }, }; @@ -64,6 +69,11 @@ test('should convert options before passing to navigator.credentials.create(...) expect(argsPublicKey.challenge).toEqual(toUint8Array(goodOpts1.publicKey.challenge)); expect(argsPublicKey.user.id).toEqual(toUint8Array(goodOpts1.publicKey.user.id)); + expect(argsPublicKey.excludeCredentials).toEqual([{ + id: base64js.toByteArray('authIdentifier=='), + type: 'public-key', + transports: ['internal'], + }]) done(); }); diff --git a/packages/browser/src/methods/startAttestation.ts b/packages/browser/src/methods/startAttestation.ts index c095670..14ffc53 100644 --- a/packages/browser/src/methods/startAttestation.ts +++ b/packages/browser/src/methods/startAttestation.ts @@ -7,6 +7,7 @@ import { import toUint8Array from '../helpers/toUint8Array'; import toBase64String from '../helpers/toBase64String'; import supportsWebauthn from '../helpers/supportsWebauthn'; +import toPublicKeyCredentialDescriptor from '../helpers/toPublicKeyCredentialDescriptor'; /** * Begin authenticator "registration" via WebAuthn attestation @@ -28,6 +29,9 @@ export default async function startAttestation( ...creationOptionsJSON.publicKey.user, id: toUint8Array(creationOptionsJSON.publicKey.user.id), }, + excludeCredentials: creationOptionsJSON.publicKey.excludeCredentials.map( + toPublicKeyCredentialDescriptor, + ), }; // Wait for the user to complete attestation |