AuthenticatorResponse: clientDataJSON 屬性
AuthenticatorResponse 介面的 clientDataJSON 屬性以 ArrayBuffer 的形式儲存一個 JSON 字串,該字串表示傳遞給 navigator.credentials.create() 或 navigator.credentials.get() 的客戶端資料。此屬性僅在 AuthenticatorResponse 的子物件上訪問,具體是 AuthenticatorAttestationResponse 或 AuthenticatorAssertionResponse。
值
一個 ArrayBuffer。
例項屬性
將 clientDataJSON 物件從 ArrayBuffer 轉換為 JavaScript 物件後,它將具有以下屬性:
challenge-
從依賴方伺服器傳送的加密挑戰的 base64url 編碼版本。原始值作為
challenge選項在CredentialsContainer.get()或CredentialsContainer.create()中傳遞。 crossOrigin可選-
一個布林值。如果設定為
true,則表示呼叫上下文是一個與祖先幀不同源的<iframe>。 origin-
客戶端/瀏覽器提供的依賴方的完全限定源。我們應該期望依賴方的 ID 是此值的字尾。
tokenBinding可選 已棄用-
一個描述與依賴方通訊的 令牌繫結協議 狀態的物件。它有兩個屬性:
status:一個字串,可以是"supported"(表示客戶端支援令牌繫結但未與依賴方協商)或"present"(表示已使用令牌繫結)。id:一個字串,是用於通訊的令牌繫結 ID 的 base64url 編碼。
如果缺少此屬性,則表示客戶端不支援令牌繫結。
注意:根據規範的 Level 3,
tokenBinding已被棄用,但該欄位被保留,以防將來用於其他目的。 topOrigin可選-
包含依賴方的完全限定頂級源。僅當
crossOrigin為true時設定。 type-
一個字串,當檢索現有憑證時為
"webauthn.get",當建立新憑證時為"webauthn.create"。
示例
js
function arrayBufferToStr(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
// pk is a PublicKeyCredential that is the result of a create() or get() Promise
const 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 challenge
console.log(clientDataObj.origin); // the window.origin
規範
| 規範 |
|---|
| Web Authentication:訪問公鑰憑證的 API - 第 3 級 # dom-authenticatorresponse-clientdatajson |
瀏覽器相容性
載入中…