PublicKeyCredential
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2021年9月.
* Some parts of this feature may have varying levels of support.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
PublicKeyCredential インターフェイスは、パスワードの代わりにフィッシングやデータ消去に耐性のある非対称の鍵ペアを使用してサービスにログインするための資格情報である、公開鍵と秘密鍵のペアについての情報を提供します。これは Credential を継承しており、ウェブ認証 API が資格情報管理 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.isUserVerifyingPlatformAuthenticatorAvailable()安全なコンテキスト用-
静的メソッドで、認証機器が所属するプラットフォームがユーザーを検証する能力を持っているならば
trueで解決するPromiseを返します。
インスタンスメソッド
PublicKeyCredential.getClientExtensionResults()安全なコンテキスト用-
何らかの拡張機能がリクエストされた場合、このメソッドはその拡張機能が処理した結果を返します。
例
>PublicKeyCredential の新しいインスタンスを生成
ここでは、 navigator.credentials.create() を用いて新しい資格情報を生成します。
const publicKey = { challenge: new Uint8Array([ 21, 31, 105 /* 29 more random bytes generated by the server */, ]), rp: { name: "Example CORP", id: "login.example.com", }, user: { id: new Uint8Array(16), name: "canand@example.com", displayName: "Carina Anand", }, pubKeyCredParams: [ { type: "public-key", alg: -7, }, ], }; navigator.credentials .create({ publicKey }) .then((newCredentialInfo) => { const response = newCredentialInfo.response; const clientExtensionsResults = newCredentialInfo.getClientExtensionResults(); }) .catch((err) => { console.error(err); }); PublicKeyCredential の既存のインスタンスを取得
ここでは、 navigator.credentials.get() を用いて認証機器から既存の資格情報を読み取ります。
const options = { challenge: new Uint8Array([ /* bytes sent from the server */ ]), }; navigator.credentials .get({ publicKey: options }) .then((credentialInfoAssertion) => { // send assertion response back to the server // to proceed with the control of the credential }) .catch((err) => { console.error(err); }); 仕様書
| Specification |
|---|
| Web Authentication: An API for accessing Public Key Credentials - Level 3> # iface-pkcredential> |
ブラウザーの互換性
関連情報
- 親インターフェイスの
Credential