Created
August 15, 2024 00:54
-
-
Save iffy/ee97eb1ff5f1702bac5c47faa46d7282 to your computer and use it in GitHub Desktop.
passkey test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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