Last active
October 21, 2020 09:46
-
-
Save prateekjadhwani/d0e07316a80616bce2e487afdc286a37 to your computer and use it in GitHub Desktop.
WebAuth Using FaceID/TouchID
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
// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential | |
// isUserVerifyingPlatformAuthenticatorAvailable() tells you if you can use a platform to authenticate the user | |
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable() | |
.then((isAvailable) => { | |
// Do Stuff with TouchID / Face ID | |
}) | |
.catch(e => { | |
// Doesnt support, bad :( | |
}); |
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
const options = { | |
publicKey: { | |
rp: { name: 'https://prateekjadhwani.github.io/touchidtest/' }, // Name of the website | |
user: { | |
name: 'username', | |
id: new Uint8Array(16), | |
displayName: 'Your Name' | |
}, | |
identifier: 'username', | |
pubKeyCredParams: [ { type: 'public-key', alg: -7 }], | |
challenge: serverChallenge, | |
authenticatorSelection: { authenticatorAttachement: 'platform' } | |
} | |
}; | |
navigator.credentials.create(options) | |
.then((newCredentialInfo) => { | |
// Do Stuff with Creds info | |
}).catch(function (err) { | |
console.error(err); | |
}); |
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
const options = { | |
publicKey: { | |
challenge: serverChallenge2, | |
allowCredentials: [{ | |
type: 'public-key', | |
id: rawIDReceivedInNewCredentialInfo, | |
transports: ['internal'], | |
}], | |
userVerification: 'preferred' | |
} | |
}; | |
navigator.credentials.get(options) | |
.then((credentialInfoAssertion) => { | |
// Success with login | |
}).catch(function (err) { | |
console.error(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment