Skip to content

Instantly share code, notes, and snippets.

@iffy
Created August 15, 2024 00:54
Show Gist options
  • Save iffy/ee97eb1ff5f1702bac5c47faa46d7282 to your computer and use it in GitHub Desktop.
Save iffy/ee97eb1ff5f1702bac5c47faa46d7282 to your computer and use it in GitHub Desktop.
passkey test case
<html>
<body>
<button id="create-button">Create Passkey</button>
<button id="test-button">Test Passkeys</button>
<script>
async function addPasskey() {
let options = {
"rp": {
"name": "Passkey Demo"
},
"user": {
"id": (new TextEncoder()).encode("123456").buffer,
"name": "a@a.com",
"displayName": "a@a.com"
},
"pubKeyCredParams": [
{
"type": "public-key",
"alg": -7
}
],
"attestation": "direct",
"challenge": (new TextEncoder()).encode("11112222333344441111222233334444").buffer,
"authenticatorSelection": {
"userVerification": "preferred"
},
"excludeCredentials": []
}
console.log(options);
let cred = await navigator.credentials.create({
publicKey: options,
})
// Pretend to save it
console.log("OK");
}
async function testPasskey() {
let options = {
"challenge": (new TextEncoder()).encode("55552222333344441111222233334444").buffer,
"authenticatorSelection": {
"userVerification": "preferred"
}
}
console.log(options);
let cred = await navigator.credentials.get({publicKey: options});
console.log("cred", cred);
console.log("OK");
}
document.getElementById('create-button').addEventListener('click', async () => {
addPasskey();
})
document.getElementById('test-button').addEventListener('click', async () => {
testPasskey();
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment