IdentityProvider

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

Giao diện IdentityProvider của Federated Credential Management (FedCM) API đại diện cho một IdP và cung cấp quyền truy cập vào thông tin và chức năng liên quan.

Phương thức tĩnh

close() Thử nghiệm

Cung cấp tín hiệu thủ công cho trình duyệt rằng luồng đăng nhập IdP đã hoàn tất. Điều này cần thiết, ví dụ, để đóng hộp thoại đăng nhập IdP khi đăng nhập hoàn tất và IdP đã thu thập xong dữ liệu từ người dùng.

getUserInfo() Thử nghiệm

Trả về thông tin về một người dùng đã đăng nhập trước đó khi họ quay lại IdP, có thể được sử dụng để hiển thị thông điệp chào mừng và nút đăng nhập được cá nhân hóa.

Ví dụ

Cách sử dụng cơ bản của IdentityProvider.getUserInfo()

Ví dụ sau đây minh họa cách phương thức getUserInfo() có thể được sử dụng để trả về thông tin về người dùng đã đăng nhập trước đó từ một IdP cụ thể.

js
// Iframe displaying a page from the https://idp.example origin
const userInfo = await IdentityProvider.getUserInfo({
  configURL: "https://idp.example/fedcm.json",
  clientId: "client1234",
});

// IdentityProvider.getUserInfo() returns an array of user information.
if (userInfo.length > 0) {
  // Returning accounts should be first, so the first account received
  // is guaranteed to be a returning account
  const name = userInfo[0].name;
  const givenName = userInfo[0].given_name;
  const displayName = givenName || name;
  const picture = userInfo[0].picture;
  const email = userInfo[0].email;

  // …

  // Render a personalized sign-in button using the information returned above
}

Thông số kỹ thuật

Thông số kỹ thuật
Federated Credential Management API
# browser-api-identity-provider-interface

Tương thích trình duyệt

Xem thêm