PublicKeyCredential:getClientExtensionResults() 方法
PublicKeyCredential 介面的 getClientExtensionResults() 方法返回一個物件,該物件將憑據建立或身份驗證期間請求的擴充套件的識別符號對映到它們被使用者代理處理後的結果。
在建立或獲取 PublicKeyCredential(分別透過 navigator.credentials.create() 和 navigator.credentials.get())時,可以透過 publicKey 選項的 extensions 屬性請求客戶端進行“自定義”處理不同的擴充套件。有關請求不同擴充套件的更多資訊,請參閱 Web 身份驗證擴充套件。
注意: getClientExtensionResults() 僅返回由使用者代理(客戶端)處理的擴充套件的結果。由身份驗證器處理的擴充套件的結果可以在 身份驗證器資料 中找到,該資料可在 AuthenticatorAssertionResponse.authenticatorData 中獲取。
語法
js
getClientExtensionResults()
引數
無。
返回值
一個物件,每個條目是擴充套件的識別符號字串作為鍵,以及客戶端處理擴充套件的輸出作為值。
異常
SecurityErrorDOMException-
RP 域無效。
示例
js
const publicKey = {
// Here are the extension "inputs"
extensions: {
appid: "https://accounts.example.com",
},
allowCredentials: {
id: "fgrt46jfgd...",
transports: ["usb", "nfc"],
type: "public-key",
},
challenge: new Uint8Array(16) /* from the server */,
};
navigator.credentials
.get({ publicKey })
.then((publicKeyCred) => {
const myResults = publicKeyCred.getClientExtensionResults();
// myResults will contain the output of processing the "appid" extension
})
.catch((err) => {
console.error(err);
});
規範
| 規範 |
|---|
| Web Authentication:訪問公鑰憑證的 API - 第 3 級 # dom-publickeycredential-getclientextensionresults |
瀏覽器相容性
載入中…
注意: 擴充套件是可選的,不同的瀏覽器可能識別不同的擴充套件。客戶端始終可以忽略處理擴充套件:如果瀏覽器不識別給定的擴充套件,它將直接忽略它。有關哪些瀏覽器支援哪些擴充套件的資訊,請參閱 Web 身份驗證擴充套件。
另見
- 當前定義的擴充套件列表
AuthenticatorAssertionResponse.authenticatorData,其中包含身份驗證器擴充套件處理的結果