Skip to content

Instantly share code, notes, and snippets.

@dannycabrera
Last active October 21, 2020 19:23
Show Gist options
  • Save dannycabrera/9774919facc66320a0eb7856ee7552ae to your computer and use it in GitHub Desktop.
Save dannycabrera/9774919facc66320a0eb7856ee7552ae to your computer and use it in GitHub Desktop.
Safari Biometric (Touch/Face ID) Testing
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; user-scalable=no; width=device-width">
<script type="text/javascript">
function testBiometrics() {
// Detects if device is on iOS
const isIos = () => {
const userAgent = window.navigator.userAgent.toLowerCase();
return /iphone|ipad|ipod/.test( userAgent );
}
const isInStandaloneMode = () => ('standalone' in window.navigator) && (window.navigator.standalone);
if (isIos()) {
if (!("TextEncoder" in window)) {
document.body.innerHTML = "This browser does not support TextEncoder...";
return;
}
var enc = new TextEncoder();
// Enrollment
const publicKey = {
rp: { name: "biometrictesting.com" },
user: {
name: "[email protected]",
id: enc.encode("12345678910"),
displayName: "Test User"
},
pubKeyCredParams: [ { type: "public-key", alg: -7 } ],
challenge: enc.encode("random_string"),
authenticatorSelection: { authenticatorAttachment: "platform" },
attestation: "direct"
};
navigator.credentials.create({publicKey}).then((newCredentialInfo) => {
alert('Success');
}).catch((error) => {
alert('Fail');
})
}
}
</script>
</head>
<body>
Biometric testing<br>
<br>
<input type="button" value="Enable Biometrics" onclick="testBiometrics()" >
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment