Created
March 12, 2019 03:38
-
-
Save achadha235/5e4b358aad1ded1fda706a9ba1ad6fa9 to your computer and use it in GitHub Desktop.
Webauthn
This file contains hidden or 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
| var createChallenge = () => window.crypto.getRandomValues(new Uint8Array(32)).buffer; | |
| var createUserId = () => new Uint8Array(16); | |
| var credential; | |
| var attestation; | |
| var assertion; | |
| var createCredentialDefaultArgs = { | |
| publicKey: { | |
| rp: { name: "Dapper" }, | |
| user: { | |
| id: createUserId(), | |
| name: "pepito.johnson@example.com", | |
| displayName: "PepitoJ" | |
| }, | |
| // SHA 256 | |
| pubKeyCredParams: [{ type: "public-key", alg: -7 }], | |
| attestation: "direct", | |
| timeout: 60000, | |
| // must be a cryptographically random number sent from a server | |
| // that is at least 16 bytes in length | |
| challenge: createChallenge() | |
| } | |
| }; | |
| navigator.credentials.create(createCredentialDefaultArgs) | |
| .then(cred => { | |
| credential = cred; | |
| console.log("CREDENTIAL:", credential); | |
| }).then(() => { | |
| var getCredentialDefaultArgs = { | |
| publicKey: { | |
| timeout: 60000, | |
| }, | |
| }; | |
| var idList = [{ | |
| id: credential.rawId, // transports: ["usb", "nfc", "ble"], | |
| type: "public-key" | |
| }]; | |
| getCredentialDefaultArgs.publicKey.allowCredentials = idList; | |
| getCredentialDefaultArgs.publicKey.challenge = createChallenge(); | |
| alert("You registerd successfully"); | |
| alert("About to login..."); | |
| navigator.credentials.get(getCredentialDefaultArgs) | |
| .then((assertion) => { | |
| alert("You logged in successfully!"); | |
| assertion = assertion; | |
| console.log("ASSERTION:", assertion); | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment