AuthenticatorResponse: clientDataJSON property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
TheclientDataJSON property of theAuthenticatorResponse interface stores aJSON string in anArrayBuffer, representing the client data that was passed tonavigator.credentials.create() ornavigator.credentials.get(). This property is only accessed on one of the child objects ofAuthenticatorResponse, specificallyAuthenticatorAttestationResponse orAuthenticatorAssertionResponse.
In this article
Value
AnArrayBuffer.
Instance properties
After theclientDataJSON object is converted from anArrayBuffer to a JavaScript object, it will have the following properties:
challengeThebase64urlencoded version of the cryptographic challenge sent from the relying party's server.The original value are passed as the
challengeoption inCredentialsContainer.get()orCredentialsContainer.create().crossOriginOptionalA boolean. If set to
true, it means that the calling context is an<iframe>that is not same origin with its ancestor frames.originThe fully qualified origin of the relying party which has been given by theclient/browser to the authenticator. We should expect therelying party'sid to be a suffix of this value.
tokenBindingOptionalDeprecatedAn object describing the state ofthe token binding protocol for the communication with the relying party. It has two properties:
status: A string which is either"supported"whichindicates the client support token binding but did not negotiate with the relyingparty or"present"when token binding was used alreadyid: A string which is thebase64urlencoding of the token binding ID which was used for the communication.
Should this property be absent, it would indicate that the client does not supporttoken binding.
Note:
tokenBindingis deprecated as of Level 3 of the spec, but the field is reserved so that it won't be reused for a different purpose.topOriginOptionalContains the fully qualified top-level origin of the relying party. It is set only if it
crossOriginistrue.typeA string which is either
"webauthn.get"when an existing credential isretrieved or"webauthn.create"when a new credential is created.
Examples
function arrayBufferToStr(buf) { return String.fromCharCode.apply(null, new Uint8Array(buf));}// pk is a PublicKeyCredential that is the result of a create() or get() Promiseconst clientDataStr = arrayBufferToStr(pk.response.clientDataJSON);const clientDataObj = JSON.parse(clientDataStr);console.log(clientDataObj.type); // "webauthn.create" or "webauthn.get"console.log(clientDataObj.challenge); // base64 encoded String containing the original challengeconsole.log(clientDataObj.origin); // the window.originSpecifications
| Specification |
|---|
| Web Authentication: An API for accessing Public Key Credentials - Level 3> # dom-authenticatorresponse-clientdatajson> |