PublicKeyCredential: response 屬性
PublicKeyCredential 介面中只讀的 response 屬性是一個 AuthenticatorResponse 物件,它由驗證器傳送給使用者代理,用於建立/獲取憑據。此響應中包含的資訊將由依賴方伺服器用於驗證請求的合法性。
AuthenticatorResponse 要麼是
- 一個
AuthenticatorAttestationResponse(當PublicKeyCredential透過CredentialsContainer.create()建立時) - 一個
AuthenticatorAssertionResponse(當PublicKeyCredential透過CredentialsContainer.get()獲取時)。
為了驗證憑據的建立,依賴方伺服器需要
- 此響應
- 客戶端的擴充套件(由
PublicKeyCredential.getClientExtensionResults()提供)來驗證請求。
注意: 在驗證現有憑據的獲取時,依賴方伺服器需要整個 PublicKeyCredential 物件以及客戶端擴充套件。
注意: 此屬性只能用於頂級上下文,在 <iframe> 中不可用。
值
一個 AuthenticatorResponse 物件,其中包含依賴方指令碼將接收到的資料,這些資料應傳送到依賴方伺服器以驗證建立或獲取請求。此物件包含來自客戶端(AuthenticatorResponse/clientDataJSON)和來自驗證器的資料。
示例
js
const options = {
challenge: new Uint8Array(16) /* from the server */,
rp: {
name: "Example CORP",
id: "login.example.com",
},
user: {
id: new Uint8Array(16) /* from the server */,
name: "canand@example.com",
displayName: "Carina Anand",
},
pubKeyCredParams: [
{
type: "public-key",
alg: -7,
},
],
};
navigator.credentials
.create({ publicKey: options })
.then((pubKeyCredential) => {
const response = pubKeyCredential.response;
const clientExtResults = pubKeyCredential.getClientExtensionResults();
// Send response and client extensions to the server so that it can validate
// and create credentials
})
.catch((err) => {
// Deal with any error
});
規範
| 規範 |
|---|
| Web Authentication:訪問公鑰憑證的 API - 第 3 級 # dom-publickeycredential-response |
瀏覽器相容性
載入中…