Skip to content

Instantly share code, notes, and snippets.

@prateekjadhwani
Last active October 21, 2020 09:46
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 prateekjadhwani/d0e07316a80616bce2e487afdc286a37 to your computer and use it in GitHub Desktop.
Save prateekjadhwani/d0e07316a80616bce2e487afdc286a37 to your computer and use it in GitHub Desktop.
WebAuth Using FaceID/TouchID
// 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 :(
});
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);
});
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