devfest-2023-webauthn/NOTES.md

1.1 KiB

npx http-server .
const challenge = Uint8Array.from("myserverchallenge", c => c.charCodeAt(0))

const userId = Uint8Array.from("myuserid", c => c.charCodeAt(0))

const options = {
    challenge,
    rp: {
        name: "localhost",
        id: "localhost",
    },
    user: {
        id: userId,
        name: "myuser",
        displayName: "John Doe",
    },
    pubKeyCredParams: [{alg: -7, type: "public-key"}],
    authenticatorSelection: {
        authenticatorAttachment: "cross-platform",
    },
    timeout: 60000,
    attestation: "direct"
};

const credential = await navigator.credentials.create({
    publicKey: options
});


var decoder = new TextDecoder()
decoder.decode(credential.response.clientDataJSON)

CBOR.decode(credential.response.attestationObject)
const newChallenge = Uint8Array.from("myservernewchallenge", c => c.charCodeAt(0))

const assertionOptions = {
    challenge: newChallenge,
    allowCredentials: [
        {
            id: credential.rawId,
            type: 'public-key'
        }
    ],
    timeout: 60000
}

navigator.credentials
  .get({ publicKey: assertionOptions })