summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/credential-management/support/fedcm/userinfo-iframe.html
blob: 45a1a34ce9e360e8eae13cb1e79c011c9b74db4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!doctype html>
<script type="module">
import {alt_manifest_origin} from './../fedcm-helper.sub.js';

// Loading fedcm-iframe.html in the test will make a FedCM call on load, and
// trigger a postMessage upon completion.
//
// message {
//   string result: "Pass" | "Fail"
//   string token: token.token
//   string errorType: error.name
// }
window.onload = async () => {
  try {
   const manifest_path = `${alt_manifest_origin}/\
credential-management/support/fedcm/manifest.py`;
    const user_info = await IdentityProvider.getUserInfo({
      configURL: manifest_path,
      // Approved client
      clientId: '123',
    });
    let results = {
      result: "Pass",
      numAccounts: user_info.length,
      firstAccountEmail: user_info[0].email,
      firstAccountName: user_info[0].name,
      firstAccountGivenName: user_info[0].givenName,
      firstAccountPicture: user_info[0].picture
    };
    window.top.postMessage(results, '*');
  } catch (error) {
    window.top.postMessage({result: "Fail", errorType: error.name}, '*');
  }
};

</script>