PublicKeyCredential

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

PublicKeyCredential インターフェイスは、パスワードの代わりにフィッシングやデータ消去に耐性のある非対称の鍵ペアを使用してサービスにログインするための資格情報である、公開鍵と秘密鍵のペアについての情報を提供します。これは Credential を継承しており、ウェブ認証 API資格情報管理 API へ拡張された際に作成されました。 Credential を継承している他のインターフェイスとしては、 PasswordCredential (en-US)FederatedCredential があります。

Credential PublicKeyCredential

メモ: このインターフェイスは最上位のコンテキストに限定されています。 <iframe> 要素の中で使用しても、何も効果がありません。

インスタンスプロパティ

PublicKeyCredential.type 読取専用 安全なコンテキスト用

Credential から継承しています。 PublicKeyCredential インスタンスの場合は、常に public-key に設定されています。

PublicKeyCredential.id 読取専用 安全なコンテキスト用

Credential から継承しており、 PublicKeyCredential.rawIdbase64url 符号化になるようオーバーライドしています。

PublicKeyCredential.rawId 読取専用 安全なコンテキスト用

ArrayBuffer で、この PublicKeyCredential のグローバルに固有な識別子を保持します。この識別子は今後の CredentialsContainer.get (en-US) の呼び出しにおいて、資格情報を検索するのに使用することができます。

PublicKeyCredential.response 読取専用 安全なコンテキスト用

AuthenticatorResponse オブジェクトのインスタンスです。これは PublicKeyCredentialnavigator.credentials.create() の呼び出しの結果だった場合であった場合は AuthenticatorAttestationResponse 型に、 PublicKeyCredentialnavigator.credentials.get() (en-US) の呼び出しの結果であった場合は 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() (en-US) を用いて認証機器から既存の資格情報を読み取ります。

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

ブラウザーの互換性

BCD tables only load in the browser

関連情報