Created
March 6, 2024 16:16
-
-
Save mingderwang/5a0776e06ffd040ca12531511b43a4fc to your computer and use it in GitHub Desktop.
on runkit
This file contains 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
exports.endpoint = (req, res) => { | |
const html = ` | |
<!-- Example 1: Preact in HTML (no build tooling required!) --> | |
<!-- View Code: https://glitch.com/edit/#!/familiar-warm-monday --> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Web Authentication Example</title> | |
</head> | |
<body> | |
<script> | |
async function createCredentials() { | |
try { | |
const publicKeyCredentialCreationOptions = { | |
challenge: new Uint8Array(32), // replace with a real challenge from your server | |
rp: { | |
name: 'Example Corporation', | |
id: 'runkit.sh', | |
}, | |
user: { | |
id: new Uint8Array(16), // replace with a real user id | |
name: 'john.doe@example.com', | |
displayName: 'John Doe', | |
}, | |
pubKeyCredParams: [ | |
{ | |
alg: -7, | |
type: "public-key" | |
}, | |
{ | |
"alg": -257, | |
"type": "public-key" | |
} | |
], | |
}; | |
const newCredential = await navigator.credentials.create({ | |
publicKey: publicKeyCredentialCreationOptions, | |
}); | |
// Handle the new credential as needed, e.g., send it to the server for verification | |
console.log('New credential created:', newCredential); | |
} catch (error) { | |
console.error('Error creating credentials:', error); | |
} | |
} | |
// Call the function when the page is loaded | |
createCredentials(); | |
</script> | |
</body> | |
</html> | |
`; | |
res.writeHead(200, { 'Content-Type': 'text/html' }); | |
res.write(html); | |
res.end(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment