From bfe14649a0ff61f681562c85da6550689088fc09 Mon Sep 17 00:00:00 2001 From: Lucas Garron Date: Mon, 6 Mar 2023 14:56:56 -0800 Subject: [PATCH] Add a `conditional-mediation-prompt-on-load` URL param to the demo. --- src/dev/demo/index.ts | 15 +++++++++++++-- src/dev/demo/state.ts | 6 ++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/dev/demo/index.ts b/src/dev/demo/index.ts index ed37591..c898cd6 100644 --- a/src/dev/demo/index.ts +++ b/src/dev/demo/index.ts @@ -14,6 +14,7 @@ import { get, parseRequestOptionsFromJSON, supported, + AuthenticationPublicKeyCredential, } from "../../webauthn-json/browser-ponyfill"; function registeredCredentials(): PublicKeyCredentialDescriptorJSON[] { @@ -44,7 +45,9 @@ async function register(): Promise { saveRegistration(await create(cco)); } -async function authenticate(): Promise { +async function authenticate(options?: { + conditionalMediation?: boolean; +}): Promise { const cro = parseRequestOptionsFromJSON({ publicKey: { challenge: "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", @@ -52,7 +55,7 @@ async function authenticate(): Promise { userVerification: "discouraged", }, }); - await get(cro); + return get(cro); } async function clear(): Promise { @@ -83,6 +86,14 @@ window.addEventListener("load", () => { document .querySelector("#supported")! .addEventListener("click", testSupported); + + if ( + new URL(location.href).searchParams.get( + "conditional-mediation-prompt-on-load", + ) === "true" + ) { + authenticate({ conditionalMediation: true }).then(console.log); + } } catch (e) { console.error(e); } diff --git a/src/dev/demo/state.ts b/src/dev/demo/state.ts index 3145dd3..8a32cde 100644 --- a/src/dev/demo/state.ts +++ b/src/dev/demo/state.ts @@ -1,6 +1,4 @@ -import { - RegistrationPublicKeyCredential, -} from "../../webauthn-json/browser-ponyfill"; +import { RegistrationPublicKeyCredential } from "../../webauthn-json/browser-ponyfill"; import type { RegistrationResponseExtendedJSON } from "../../webauthn-json/browser-ponyfill.extended"; export function getRegistrations(): RegistrationResponseExtendedJSON[] { @@ -37,7 +35,7 @@ export function displayRegistrations() { registrationElem().value = JSON.stringify(getRegistrations(), null, " "); } -export function withStatus(selector: string, fn: () => Promise) { +export function withStatus(selector: string, fn: () => Promise) { return async function () { document.querySelector("#error")!.textContent = ""; document.querySelector(selector)!.textContent = "…";