Last active
January 20, 2019 17:22
-
-
Save yackermann/eaf60dd974bcf16e03774f49da68eca4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById('login').addEventListener('submit', function(event) { | |
event.preventDefault(); | |
let username = this.username.value; | |
let password = this.password.value; | |
loginPassword({username, password}) | |
.then((serverResponse) => { | |
if(serverResponse.status !== 'startFIDOAuthentication') | |
throw new Error('Error logging in! Server returned: ' + serverResponse.errorMessage); | |
return getGetAssertionChallenge() | |
}) | |
.then((getAssertionChallenge) => { | |
/* Server GetAssertion sample */ | |
/*{ | |
"challenge": "Ld0vp5byLeFZBOpclgKP3BEc8AA4aBewYPlwbkgLh98", | |
"allowCredentials": [ | |
{ | |
"type": "public-key", | |
"id": "SIT9gAgwUyzOLB_F9fA_LwMOu--dcXHSlzvEXipg2QP3-Shr5f-nldK5V1Wc9BdiMDkkSpK0uPmsLb-CYigbog" | |
} | |
], | |
"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