Update passkey.service.ts

This commit is contained in:
Baobhan Sith
2025-05-08 15:23:23 +08:00
parent af417af7b6
commit 0f80c77e60
@@ -236,23 +236,24 @@ export class PasskeyService {
authenticatorTransports = undefined; authenticatorTransports = undefined;
} }
const authenticatorObject = { // This object structure should match what @simplewebauthn/server expects for its `credential` option parameter.
credentialID: authenticatorCredentialID, // Specifically, it expects `id`, `publicKey`, and `counter`.
credentialPublicKey: authenticatorPublicKey, const credentialObjectForLibrary = {
id: authenticatorCredentialID, // Renamed from credentialID
publicKey: authenticatorPublicKey, // Renamed from credentialPublicKey
counter: passkey.counter, counter: passkey.counter,
transports: authenticatorTransports, transports: authenticatorTransports,
credentialBackedUp: !!passkey.backed_up, credentialBackedUp: !!passkey.backed_up,
// Ensure credentialDeviceType is one of the allowed string literals
credentialDeviceType: (passkey.backed_up ? 'multiDevice' : 'singleDevice') as 'multiDevice' | 'singleDevice', credentialDeviceType: (passkey.backed_up ? 'multiDevice' : 'singleDevice') as 'multiDevice' | 'singleDevice',
}; };
console.log('[PasskeyService] Authenticator object to be used for verification:'); console.log('[PasskeyService] Credential object to be used for verification (passed as `credential` to library):');
console.log(` - credentialID (type: ${typeof authenticatorObject.credentialID}, instanceof Uint8Array: ${authenticatorObject.credentialID instanceof Uint8Array}, length: ${authenticatorObject.credentialID?.length}):`, authenticatorObject.credentialID); console.log(` - id (type: ${typeof credentialObjectForLibrary.id}, instanceof Uint8Array: ${credentialObjectForLibrary.id instanceof Uint8Array}, length: ${credentialObjectForLibrary.id?.length}):`, credentialObjectForLibrary.id);
console.log(` - credentialPublicKey (type: ${typeof authenticatorObject.credentialPublicKey}, instanceof Uint8Array: ${authenticatorObject.credentialPublicKey instanceof Uint8Array}, instanceof Buffer: ${authenticatorObject.credentialPublicKey instanceof Buffer}, length: ${authenticatorObject.credentialPublicKey?.length}):`, authenticatorObject.credentialPublicKey); console.log(` - publicKey (type: ${typeof credentialObjectForLibrary.publicKey}, instanceof Uint8Array: ${credentialObjectForLibrary.publicKey instanceof Uint8Array}, instanceof Buffer: ${credentialObjectForLibrary.publicKey instanceof Buffer}, length: ${credentialObjectForLibrary.publicKey?.length}):`, credentialObjectForLibrary.publicKey);
console.log(` - counter (type: ${typeof authenticatorObject.counter}):`, authenticatorObject.counter); console.log(` - counter (type: ${typeof credentialObjectForLibrary.counter}):`, credentialObjectForLibrary.counter);
console.log(` - transports (type: ${typeof authenticatorObject.transports}):`, authenticatorObject.transports); console.log(` - transports (type: ${typeof credentialObjectForLibrary.transports}):`, credentialObjectForLibrary.transports);
console.log(` - credentialBackedUp (type: ${typeof authenticatorObject.credentialBackedUp}):`, authenticatorObject.credentialBackedUp); console.log(` - credentialBackedUp (type: ${typeof credentialObjectForLibrary.credentialBackedUp}):`, credentialObjectForLibrary.credentialBackedUp);
console.log(` - credentialDeviceType (type: ${typeof authenticatorObject.credentialDeviceType}):`, authenticatorObject.credentialDeviceType); console.log(` - credentialDeviceType (type: ${typeof credentialObjectForLibrary.credentialDeviceType}):`, credentialObjectForLibrary.credentialDeviceType);
// Reverting to 'any' for verifyOpts due to issues with the library's // Reverting to 'any' for verifyOpts due to issues with the library's
// type definitions for VerifyAuthenticationResponseOpts not recognizing 'authenticator' key. // type definitions for VerifyAuthenticationResponseOpts not recognizing 'authenticator' key.
@@ -262,7 +263,7 @@ export class PasskeyService {
expectedChallenge, expectedChallenge,
expectedOrigin: RP_ORIGIN, expectedOrigin: RP_ORIGIN,
expectedRPID: RP_ID, expectedRPID: RP_ID,
authenticator: authenticatorObject, credential: credentialObjectForLibrary, // Renamed from authenticator to credential
requireUserVerification: true, requireUserVerification: true,
}; };
console.log('[PasskeyService] verifyOpts to be passed to @simplewebauthn/server (using type any):', JSON.stringify(verifyOpts, (key, value) => { console.log('[PasskeyService] verifyOpts to be passed to @simplewebauthn/server (using type any):', JSON.stringify(verifyOpts, (key, value) => {