Credential

Baseline Widely available *

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

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

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Giao diện Credential của Credential Management API cung cấp thông tin về một thực thể (thường là người dùng), thường như một điều kiện tiên quyết để đưa ra quyết định về mức độ tin cậy.

Các đối tượng Credential có thể thuộc các kiểu sau:

Thuộc tính thể hiện

Credential.id Read only

Trả về một chuỗi chứa định danh của thông tin xác thực. Đây có thể là GUID, tên người dùng hoặc địa chỉ email.

Credential.type Read only

Trả về một chuỗi chứa kiểu của thông tin xác thực. Các giá trị hợp lệ là password, federated, public-key, identityotp. (Dành cho PasswordCredential, FederatedCredential, PublicKeyCredential, IdentityCredentialOTPCredential)

Phương thức tĩnh

Credential.isConditionalMediationAvailable() Experimental

Trả về một Promise luôn được giải quyết thành false. Các lớp con có thể ghi đè giá trị này.

Ví dụ

js
const pwdCredential = new PasswordCredential({
  id: "example-username", // Tên người dùng/ID
  name: "Carina Anand", // Tên hiển thị
  password: "correct horse battery staple", // Mật khẩu
});

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

Thông số kỹ thuật

Specification
Credential Management Level 1
# the-credential-interface

Khả năng tương thích của trình duyệt