Skip to content

Support enabling WebAuthn for passkey authentication with a virtual authenticator #688

@tobeycodes

Description

@tobeycodes

It would be great if we could expose an action that would enable WebAuthn and adds a virtual authenticator. This will allow agents to test authentication that use passkeys.

If you are open to this I can create a pull request for this functionality.

// Example pseudocode 
const cdp = await this.getCDPSession();
await cdp.send("WebAuthn.enable")
await cdp.send("WebAuthn.addVirtualAuthenticator", {
  options: {
    protocol: "ctap2",
    transport: "internal",
    hasResidentKey: true,
    hasUserVerification: true,
    isUserVerified: true,
  },
})

Current workaround:

async function openBrowser() {
  await runAgentBrowser([
    "--args",
    "--remote-debugging-port=9333",
    "open",
    "http://localhost:3000/signup",
  ])
  await runAgentBrowser(["wait", "--load", "networkidle"])

  const response = await fetch("http://127.0.0.1:9333/json")
  const [{ webSocketDebuggerUrl }] = await response.json()
  const socket = new WebSocket(webSocketDebuggerUrl)
  await new Promise<void>((resolve) => (socket.onopen = () => resolve()))

  async function send(method: string, params: object = {}) {
    const id = Math.floor(Math.random() * 1e9)

    await new Promise<void>((resolve) => {
      socket.onmessage = (event) => {
        if (JSON.parse(String(event.data)).id === id) {
          resolve()
        }
      }
      socket.send(JSON.stringify({ id, method, params }))
    })
  }

  await send("WebAuthn.enable")
  await send("WebAuthn.addVirtualAuthenticator", {
    options: {
      protocol: "ctap2",
      transport: "internal",
      hasResidentKey: true,
      hasUserVerification: true,
      isUserVerified: true,
    },
  })

  return socket
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions