webauthn-open-source / fido2-lib

A node.js library for performing FIDO 2.0 / WebAuthn server functionality
https://webauthn.io
MIT License
394 stars 118 forks source link

Error: expectation did not contain value for 'userHandle' #155

Open lilac-milena opened 5 months ago

lilac-milena commented 5 months ago

When I try to call the assertionResult function, I got the following error: image

Here's some contextual code that may be relevant to the issue:

const assertionExpectations = {
        // Remove the following comment if allowCredentials has been added into authnOptions so the credential received will be validate against allowCredentials array.
        // allowCredentials: [],
        // userVerification: "required",
        challenge: systemFunction.base64ToUint8Array(challenge),
        origin: "https://*",
        factor: "either",
        publicKey: logingAccount["publicKey"],
        prevCounter: logingAccount["counter"]
    };

    const keyDataDecoded = {
        rawId: systemFunction.base64ToArrayBuffer(keyData.rawId),
        response: {
            authenticatorData: systemFunction.base64ToArrayBuffer(keyData.response.authenticatorData),
            signature: systemFunction.base64ToArrayBuffer(keyData.response.signature),
            userHandle: systemFunction.base64ToArrayBuffer(keyData.response.userHandle),
            clientDataJSON: systemFunction.base64ToArrayBuffer(keyData.response.clientDataJSON),
        },
        id: keyData.id,
        type: keyData.type,
    }

    //console.log(keyDataDecoded)

    const authnResult = await f2l.assertionResult(keyDataDecoded, assertionExpectations);
const f2l = new Fido2Lib({
    timeout: 42000,
    rpId: "*",
    rpName: "Identity",
    // rpIcon: "https://example.com/logo.png",
    challengeSize: 128,
    attestation: "none",
    cryptoParams: [-7, -257],
    // authenticatorAttachment: "cross-platform",
    authenticatorRequireResidentKey: true,
    requireResidentKey: true,
    userVerification: "required"
    // requireResidentKey: true,
    // authenticatorUserVerification: "required"
});

I've checked my runtime environment, I'm using the Webauthn debugging tool for Chrome to debug, and the debugging tool shows that the "User Handle" parameter is already available image

image
JamesCullum commented 5 months ago

Is this related to your PR https://github.com/webauthn-open-source/fido2-lib/pull/154 ?

lilac-milena commented 5 months ago

Is this related to your PR https://github.com/webauthn-open-source/fido2-lib/pull/154 ?

No, they're not related, it's a separate issue.

Jaepe commented 1 month ago

In your "assertionExpectations" JSON, include the user's userHandle, which is the user's ID used at signup encoded as base64url.