Skip to content

Instantly share code, notes, and snippets.

@yackermann
Last active January 4, 2019 20:19
Show Gist options
  • Save yackermann/9f9119dbf20c5996e639424e9f9734f8 to your computer and use it in GitHub Desktop.
Save yackermann/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': '[email protected]',
'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