Skip to content

Instantly share code, notes, and snippets.

@herrjemand
Created December 3, 2018 20:35
Show Gist options
  • Save herrjemand/c0f31e68f312d9f9eaa7af798b39d3ae to your computer and use it in GitHub Desktop.
Save herrjemand/c0f31e68f312d9f9eaa7af798b39d3ae to your computer and use it in GitHub Desktop.
var randomChallengeBuffer = new Uint8Array(32);
window.crypto.getRandomValues(randomChallengeBuffer);
var base64id = 'MIIBkzCCATigAwIBAjCCAZMwggE4oAMCAQIwggGTMII='
var idBuffer = Uint8Array.from(window.atob(base64id), c=>c.charCodeAt(0))
var publicKey = {
challenge: randomChallengeBuffer,
rp: {
name: 'FIDO Example Corporation',
icon: 'https://fidoalliance.co.nz/testimages/catimage.png'
},
user: {
id: idBuffer,
name: "alice@example.com",
displayName: "Alice von Wunderland",
icon: 'https://fidoalliance.co.nz/testimages/catimage.png'
},
attestation: 'direct',
authenticatorSelection: {
'authenticatorAttachment': 'platform'
},
pubKeyCredParams: [
{ type: 'public-key', alg: -7 }, // ES256
{ type: 'public-key', alg: -257 } // RS256
]
}
navigator.credentials.create({ publicKey })
.then((newCredentialInfo) => {
console.log('SUCCESS', newCredentialInfo)
})
.catch((error) => {
console.log('FAIL', error)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment