Skip to content

Conversation

Keroosha
Copy link
Contributor

@Keroosha Keroosha commented Jul 21, 2025

Fixes #2298

createPublicKeyCredential doesn't implement toJSON method from PublicKeyCredential prototype PublicKeyCredential: toJSON method at developer.mozilla.org

This PR implements that method by manually mapping PublicKeyCredentialJSON model

Testing strategy

Repro at webauthn-tojson.cybergulag.today

I patched Webauthn.NET demo to use PublicKeyCredential.toJSON method on completeAuthentication and completeRegistration steps
WebAuthn.NET lib.js

Passwordless and Usernameless flow should work fine on PR version

1.9.9.1 release will fail on missing toJSON method as mentioned in #2298

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)

@Keroosha Keroosha marked this pull request as ready for review July 22, 2025 14:49
@Keroosha Keroosha changed the title toJSON implementation for AuthenticatorAttestation and AuthenticatorAssertion toJSON implementation for createPublicKeyCredential Jul 22, 2025
@varjolintu varjolintu self-requested a review September 14, 2025 09:01
signature: kpxcArrayBufferToBase64Url(response.signature),
userHandle,
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing ;.

publicKeyAlgorithm: response.getPublicKeyAlgorithm(),
attestationObject: kpxcArrayBufferToBase64Url(response.attestationObject),
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing ;.

clientExtensionResults,
type,
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing ;.

return kpxcStringToArrayBuffer(window.atob(str?.replaceAll('-', '+').replaceAll('_', '/')));
};

const kpxcArrayBufferToBase64Url = function (buff) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy this function directly from passkey-utils.js.

@varjolintu varjolintu added this to the 1.9.11 milestone Oct 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: 'toJSON' called on an object that does not implement interface PublicKeyCredential.

2 participants