From eddc4b1b761b5ada330d83e7bc5fe56934bb097b Mon Sep 17 00:00:00 2001 From: tone Date: Thu, 18 Dec 2025 22:41:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=8E=E7=AB=AF=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=80=9A=E8=A1=8C=E8=AF=81=E5=85=AC=E9=92=A5=E5=AD=98=E5=8F=96?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/backend/src/auth/service/passkey.service.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/backend/src/auth/service/passkey.service.ts b/apps/backend/src/auth/service/passkey.service.ts index aaadb4a..c448177 100644 --- a/apps/backend/src/auth/service/passkey.service.ts +++ b/apps/backend/src/auth/service/passkey.service.ts @@ -5,7 +5,7 @@ import { Repository } from "typeorm"; import { User } from "src/user/entities/user.entity"; import { randomBytes } from 'crypto'; import { generateAuthenticationOptions, GenerateAuthenticationOptionsOpts, generateRegistrationOptions, GenerateRegistrationOptionsOpts, VerifiedAuthenticationResponse, VerifiedRegistrationResponse, verifyAuthenticationResponse, verifyRegistrationResponse } from "@simplewebauthn/server"; - +import { isoBase64URL } from '@simplewebauthn/server/helpers'; interface ChallengeEntry { value: string; @@ -156,7 +156,7 @@ export class PasskeyService implements OnModuleDestroy { user: { userId } as User, name: name || '新的通行证', credentialId: credential.id, - publicKey: credential.publicKey.toString(), + publicKey: isoBase64URL.fromBuffer(credential.publicKey), signCount: credential.counter, verified: true, }); @@ -169,8 +169,6 @@ export class PasskeyService implements OnModuleDestroy { async getAuthenticationOptions(sessionId: string) { const challenge = this.generateChallenge(); - authenticationChallenges.set(sessionId, challenge); - const opts: GenerateAuthenticationOptionsOpts = { rpID: this.rpID, challenge, @@ -178,7 +176,9 @@ export class PasskeyService implements OnModuleDestroy { userVerification: 'preferred', }; - return generateAuthenticationOptions(opts); + const options = await generateAuthenticationOptions(opts); + authenticationChallenges.set(sessionId, options.challenge); + return options; } async login(sessionId: string, credentialResponse: any): Promise { @@ -206,7 +206,7 @@ export class PasskeyService implements OnModuleDestroy { expectedRPID: this.rpID, credential: { id: passkey.credentialId, - publicKey: Buffer.from(passkey.publicKey), + publicKey: isoBase64URL.toBuffer(passkey.publicKey), counter: passkey.signCount, }, requireUserVerification: false,