Skip to content

Instantly share code, notes, and snippets.

@herrjemand
Last active January 20, 2019 17:23
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/720f62ba810acfc81339c2164ea0301d to your computer and use it in GitHub Desktop.
Save herrjemand/720f62ba810acfc81339c2164ea0301d to your computer and use it in GitHub Desktop.
document.getElementById('login').addEventListener('submit', function(event) {
event.preventDefault();
return getGetAssertionChallenge()
.then((getAssertionChallenge) => {
/*{
"challenge": "Ld0vp5byLeFZBOpclgKP3BEc8AA4aBewYPlwbkgLh98",
"status": "ok"
}*/
getAssertionChallenge = preformatGetAssertReq(getAssertionChallenge);
return navigator.credentials.get({ 'publicKey': getAssertionChallenge })
})
.then((newCredentialInfo) => {
newCredentialInfo = publicKeyCredentialToJSON(newCredentialInfo)
return getAssertionResponse(newCredentialInfo)
})
.then((serverResponse) => {
if(serverResponse.status !== 'ok')
throw new Error('Error registering user! Server returned: ' + serverResponse.errorMessage);
alert('Success!');
})
.catch((error) => {
alert('FAIL' + error)
console.log('FAIL', error)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment