Credential

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

* Some parts of this feature may have varying levels of support.

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

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

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

实例属性

Credential.id 只读

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

Credential.type 只读

返回包含凭据类型的字符。有效值为 passwordfederatedpublic-keyidentityotp。(分别对应 PasswordCredentialFederatedCredentialPublicKeyCredentialIdentityCredentialOTPCredential

实例方法

无。

示例

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

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Credential
id
isConditionalMediationAvailable() static method
Experimental
type

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.