Skip to content

Create npm-publish-github-packages.yml #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Horlabrainmoore
Copy link

Install OTP CLI helper

npm install -g otplib-cli

Generate a TOTP token from a known secret

otplib totp --secret=KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD

📌 Resources

# Install OTP CLI helper
npm install -g otplib-cli
# Generate a TOTP token from a known secret
otplib totp --secret=KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD
@Horlabrainmoore
Copy link
Author

// 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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant