Skip to content

Instantly share code, notes, and snippets.

@herrjemand
Last active January 4, 2019 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herrjemand/9f9119dbf20c5996e639424e9f9734f8 to your computer and use it in GitHub Desktop.
Save herrjemand/9f9119dbf20c5996e639424e9f9734f8 to your computer and use it in GitHub Desktop.
var challenge = new Uint8Array(32);
window.crypto.getRandomValues(challenge);
var userID = 'Kosv9fPtkDoh4Oz7Yq/pVgWHS8HhdlCto5cR0aBoVMw='
var id = Uint8Array.from(window.atob(userID), c=>c.charCodeAt(0))
var publicKey = {
'challenge': challenge,
'rp': {
'name': 'Example Inc.'
},
'user': {
'id': id,
'name': 'alice@example.com',
'displayName': 'Alice Liddell'
},
'pubKeyCredParams': [
{ 'type': 'public-key', 'alg': -7 },
{ 'type': 'public-key', 'alg': -257 }
],
'attestation': 'direct'
}
navigator.credentials.create({ 'publicKey': 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