diff options
author | Matthew Miller <matthew@millerti.me> | 2022-12-10 22:40:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-10 22:40:45 -0800 |
commit | 461b67c0c6fadfb55c1da6c9c8ab2693ba4c9a03 (patch) | |
tree | ae713d608966ac977390e7bbfbeab5ea79a191bc /packages/server/src/authentication/generateAuthenticationOptions.ts | |
parent | 33528afe001d4aca62052dce204c0398c3127ffd (diff) | |
parent | 90dd7f247182329987a8e23f476d9280d8d5c265 (diff) |
Merge pull request #299 from MasterKale/feat/isomorphic
feat/isomorphic
Diffstat (limited to 'packages/server/src/authentication/generateAuthenticationOptions.ts')
-rw-r--r-- | packages/server/src/authentication/generateAuthenticationOptions.ts | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/packages/server/src/authentication/generateAuthenticationOptions.ts b/packages/server/src/authentication/generateAuthenticationOptions.ts index b80473e..bd517e3 100644 --- a/packages/server/src/authentication/generateAuthenticationOptions.ts +++ b/packages/server/src/authentication/generateAuthenticationOptions.ts @@ -4,13 +4,13 @@ import type { PublicKeyCredentialDescriptorFuture, UserVerificationRequirement, } from '@simplewebauthn/typescript-types'; -import base64url from 'base64url'; +import { isoBase64URL, isoUint8Array } from '../helpers/iso'; import { generateChallenge } from '../helpers/generateChallenge'; export type GenerateAuthenticationOptionsOpts = { allowCredentials?: PublicKeyCredentialDescriptorFuture[]; - challenge?: string | Buffer; + challenge?: string | Uint8Array; timeout?: number; userVerification?: UserVerificationRequirement; extensions?: AuthenticationExtensionsClientInputs; @@ -42,11 +42,19 @@ export function generateAuthenticationOptions( rpID, } = options; + /** + * Preserve ability to specify `string` values for challenges + */ + let _challenge = challenge; + if (typeof _challenge === 'string') { + _challenge = isoUint8Array.fromUTF8String(_challenge); + } + return { - challenge: base64url.encode(challenge), + challenge: isoBase64URL.fromBuffer(_challenge), allowCredentials: allowCredentials?.map(cred => ({ ...cred, - id: base64url.encode(cred.id as Buffer), + id: isoBase64URL.fromBuffer(cred.id as Uint8Array), })), timeout, userVerification, |