PublicKeyCredential
安全なコンテキスト用
この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
PublicKeyCredential
インターフェイスは、パスワードの代わりにフィッシングやデータ消去に耐性のある非対称の鍵ペアを使用してサービスにログインするための資格情報である、公開鍵と秘密鍵のペアについての情報を提供します。これは Credential
を継承しており、 Web Authentication API が Credential Management API へ拡張された際に作成されました。 Credential
を継承している他のインターフェイスとしては、 PasswordCredential
や FederatedCredential
があります。
メモ: このインターフェイスは最上位のコンテキストに限定されています。 <iframe>
要素の中で使用しても、何も効果がありません。
プロパティ
PublicKeyCredential.type
読取専用 安全なコンテキスト用Credential
から継承しています。PublicKeyCredential
の場合は、常にpublic-key
に設定されています。PublicKeyCredential.id
読取専用 安全なコンテキスト用Credential
から継承しており、PublicKeyCredential.rawId
の base64url 符号化になるようオーバーライドしています。PublicKeyCredential.rawId
読取専用 安全なコンテキスト用ArrayBuffer
型で、このPublicKeyCredential
のグローバルに固有な識別子を保持します。この識別子は今後のCredentialsContainer.get
の呼び出しにおいて、資格情報を検索するのに使用することができます。PublicKeyCredential.response
読取専用 安全なコンテキスト用AuthenticatorResponse
オブジェクトのインスタンスです。これはPublicKeyCredential
がnavigator.credentials.create()
の呼び出しの結果だった場合であった場合はAuthenticatorAttestationResponse
型に、PublicKeyCredential
がnavigator.credentials.get()
の呼び出しの結果であった場合はAuthenticatorAssertionResponse
型になります。
メソッド
PublicKeyCredential.getClientExtensionResults()
安全なコンテキスト用- 何らかの拡張機能がリクエストされた場合、このメソッドはその拡張機能が処理した結果を返します。
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
安全なコンテキスト用- 静的メソッドで、認証機器が所属するプラットフォームがユーザーを検証する能力を持っているならば
true
で解決するPromise
を返します。現在の実装状況では、このメソッドは Windows Hello がシステムで利用可能な場合のみtrue
で解決します。
例
PublicKeyCredential の新しいインスタンスを生成
ここでは、 navigator.credentials.create()
を用いて新しい資格情報を生成します。
var publicKey = {
challenge: /* from the server */,
rp: {
name: "Example CORP",
id : "login.example.com"
},
user: {
id: new Uint8Array(16),
name: "jdoe@example.com",
displayName: "John Doe"
},
pubKeyCredParams: [
{
type: "public-key",
alg: -7
}
]
};
navigator.credentials.create({ publicKey })
.then(function (newCredentialInfo) {
var response = newCredentialInfo.response;
var clientExtensionsResults = newCredentialInfo.getClientExtensionResults();
}).catch(function (err) {
console.error(err);
});
PublicKeyCredential の既存のインスタンスを取得
ここでは、 navigator.credentials.get()
を用いて認証機器から既存の資格情報を読み取ります。
var options = {
challenge: new Uint8Array([/* bytes sent from the server */])
};
navigator.credentials.get({ "publicKey": options })
.then(function (credentialInfoAssertion) {
// send assertion response back to the server
// to proceed with the control of the credential
}).catch(function (err) {
console.error(err);
});
仕様書
仕様書 | 状態 | 備考 |
---|---|---|
Web Authentication: An API for accessing Public Key Credentials Level 1 PublicKeyCredential interface の定義 |
勧告 | 初回定義 |
ブラウザーの互換性
BCD tables only load in the browser
関連情報
- 親インターフェイスの
Credential