summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/authentication/generateAuthenticationOptions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src/authentication/generateAuthenticationOptions.ts')
-rw-r--r--packages/server/src/authentication/generateAuthenticationOptions.ts16
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,