Skip to content

Commit

Permalink
Enhance WebAuthn authentication verification with detailed logging an…
Browse files Browse the repository at this point in the history
…d config
  • Loading branch information
kentcdodds committed Feb 7, 2025
1 parent 183c1a8 commit cd5250a
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions app/routes/resources+/webauthn+/verify-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { z } from 'zod'
import { prisma } from '#app/utils/prisma.server.ts'
import { getSession } from '#app/utils/session.server.ts'
import { passkeyCookie } from '#app/utils/webauthn.server.ts'
import { getWebAuthnConfig, passkeyCookie } from '#app/utils/webauthn.server.ts'

const AuthenticationResponseSchema = z.object({
id: z.string(),
Expand Down Expand Up @@ -52,11 +52,38 @@ export async function action({ request }: ActionFunctionArgs) {
throw new Error('Passkey not found')
}

const config = getWebAuthnConfig(request)

// TODO: remove this log
const decodedResponseData = {
id: result.data.id,
rawId: result.data.rawId,
response: {
authenticatorData: result.data.response.authenticatorData,
clientDataJSON: JSON.parse(
Buffer.from(
result.data.response.clientDataJSON,
'base64url',
).toString(),
),
signature: Buffer.from(
result.data.response.signature,
'base64url',
).toString('hex'),
userHandle: result.data.response.userHandle
? Buffer.from(result.data.response.userHandle, 'base64url').toString()
: undefined,
},
type: result.data.type,
clientExtensionResults: result.data.clientExtensionResults,
}
console.log('Decoded authentication response:', decodedResponseData)

const verification = await verifyAuthenticationResponse({
response: result.data,
expectedChallenge: cookie.challenge,
expectedOrigin: new URL(request.url).origin,
expectedRPID: new URL(request.url).hostname,
expectedOrigin: config.origin,
expectedRPID: config.rpID,
credential: {
id: result.data.id,
publicKey: passkey.publicKey,
Expand Down

0 comments on commit cd5250a

Please sign in to comment.