Credential

Baseline 广泛可用 *

此功能已成熟,并可在多种设备和浏览器版本上使用。自 2019 年 9 月以来,它已在各种浏览器中可用。

* 此特性的某些部分可能存在不同级别的支持。

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

Credential 接口是 凭证管理 API 的一部分,它提供有关一个实体(通常是用户)的信息,这通常是做出信任决策的前提。

Credential 对象可以是以下类型:

实例属性

Credential.id 只读

返回一个包含凭证标识符的字符串。这可能是一个 GUID、用户名或电子邮件地址。

Credential.type 只读

返回一个包含凭证类型的字符串。有效值为 passwordfederatedpublic-keyidentityotp。(适用于 PasswordCredentialFederatedCredentialPublicKeyCredentialIdentityCredentialOTPCredential

静态方法

Credential.isConditionalMediationAvailable() 实验性

返回一个 Promise,它始终解析为 false。子类可以覆盖此值。

示例

js
const pwdCredential = new PasswordCredential({
  id: "example-username", // Username/ID
  name: "Carina Anand", // Display name
  password: "correct horse battery staple", // Password
});

console.assert(pwdCredential.type === "password");

规范

规范
Credential Management Level 1
# the-credential-interface

浏览器兼容性