Create npm-publish-github-packages.yml
Install OTP CLI helper
npm install -g otplib-cli
Generate a TOTP token from a known secret
otplib totp --secret=KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD
📌 Resources
// File: routes/webauthn.ts
import express from 'express'; import { generateRegistrationOptions, verifyRegistrationResponse, generateAuthenticationOptions, verifyAuthenticationResponse, } from '@simplewebauthn/server'; import base64url from 'base64url';
const router = express.Router(); const users: Record<string, any> = {};
router.post('/generate-registration-options', (req, res) => { const { username } = req.body; const user = (users[username] = users[username] || { id: base64url(Buffer.from(username)), credentials: [] });
const options = generateRegistrationOptions({ rpName: 'Cody Auth Stack', userID: user.id, userName: username, attestationType: 'indirect', });
user.challenge = options.challenge; res.json(options); });
router.post('/verify-registration', async (req, res) => { const { body } = req; const user = users[body.username];
const verification = await verifyRegistrationResponse({ response: body.attestationResponse, expectedChallenge: user.challenge, expectedOrigin: 'http://localhost:3000', expectedRPID: 'localhost', });
if (verification.verified) { user.credentials.push(verification.registrationInfo); }
res.json({ verified: verification.verified }); });
router.post('/generate-authentication-options', (req, res) => { const { username } = req.body; const user = users[username];
const options = generateAuthenticationOptions({ allowCredentials: user.credentials.map((cred: any) => ({ id: cred.credentialID, type: 'public-key', })), });
user.challenge = options.challenge; res.json(options); });
router.post('/verify-authentication', async (req, res) => { const { body } = req; const user = users[body.username];
const verification = await verifyAuthenticationResponse({ response: body.assertionResponse, expectedChallenge: user.challenge, expectedOrigin: 'http://localhost:3000', expectedRPID: 'localhost', authenticator: user.credentials[0], });
res.json({ verified: verification.verified }); });
export default router;
It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!
To keep things tidy, we are closing this issue for now. If you think your issue is still relevant, leave a comment and we might reopen it. Thanks!