Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
document.getElementById('login').addEventListener('submit', function(event) {
event.preventDefault();
let username = this.username.value;
startAuthenticationPasswordless({username})
.then((serverResponse) => {
if(serverResponse.status !== 'startFIDOAuthentication')
throw new Error('Error logging in! Server returned: ' + serverResponse.errorMessage);
return getGetAssertionChallenge()
})
.then((getAssertionChallenge) => {
/*{
"challenge": "Ld0vp5byLeFZBOpclgKP3BEc8AA4aBewYPlwbkgLh98",
"allowCredentials": [
{
"type": "public-key",
"id": "SIT9gAgwUyzOLB_F9fA_LwMOu--dcXHSlzvEXipg2QP3-Shr5f-nldK5V1Wc9BdiMDkkSpK0uPmsLb-CYigbog"
}
],
"userVerification": "required",
"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