Credential

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

Credential Management APICredential 接口提供有关实体(通常是用户)的信息,通常作为信任决策的先决条件。

Credential 对象可以是以下这些类型:

实例属性

Credential.id 只读

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

Credential.type 只读

返回包含凭据类型的字符。有效值为 passwordfederatedpublic-keyidentityotp。(分别对应 PasswordCredential (en-US)FederatedCredential (en-US)PublicKeyCredential (en-US)IdentityCredential (en-US)OTPCredential (en-US)

实例方法

无。

示例

js
const pwdCredential = new PasswordCredential({
  id: "example-username", // 用户名 / ID
  name: "Carina Anand", // 显示名称
  password: "correct horse battery staple", // 密码
});

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

规范

Specification
Credential Management Level 1
# the-credential-interface

浏览器兼容性

BCD tables only load in the browser