Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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: "testuser@biometrictesting.com",
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