-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.html
90 lines (79 loc) · 4.04 KB
/
index.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AppAuth Client</title>
<style>
#userDetails {
display:block;
width:600px;
height:400px;
background-color:lightgray;
font-family: monospace;
white-space: pre;
padding: 10px;
}
</style>
</head>
<body>
<div id="userDetails"></div>
<a href='#' onclick='AppAuthHelper.logout(({ revoke_tokens: true, end_session: true }).then(function () { location.reload(); }); return false;'>Logout</a>
</body>
<script src="appAuthHelperBundle.js"></script>
<script>
(function () {
AppAuthHelper.init({
clientId: "appAuthClient",
authorizationEndpoint: "https://default.iam.example.com/am/oauth2/authorize",
tokenEndpoint: "https://default.iam.example.com/am/oauth2/access_token",
revocationEndpoint: "https://default.iam.example.com/am/oauth2/token/revoke",
endSessionEndpoint: "https://default.iam.example.com/am/oauth2/connect/endSession",
// Use a redirectUri hosted on a different origin to get XSS protection for your access tokens
// Be sure to adjust the TRUSTED_ORIGIN value within appAuthHelperRedirect.html to point back to this origin
//redirectUri: "http://appauthclient.example.com:8888/appAuthHelperRedirect.html",
resourceServers: {
"https://default.iam.example.com/am/oauth2/userinfo": "profile",
"https://default.iam.example.com/openidm": "fr:idm:*"
},
/*
interactionRequiredHandler: function (authorization_request_url, error_reported) {
// If you want to handle login at the IDP using some mechanism other than
// the default (standard OAuth2 redirection to the authorizationEndpoint),
// you can add that logic here.
// Call AppAuthHelper.getTokens(); again when login is finished.
},
*/
tokensAvailableHandler: function (claims, id_token, interactively_logged_in) {
// This is a great place to startup the parts of your SPA that are for logged-in users.
// The "claims" parameter is the content of the id_token, which tells you useful details
// about the logged-in user. It will be undefined if you aren't using OIDC.
// The "id_token" is the actual id_token value, which can be useful to have in its original form
// for various use-cases; OP-based session management may be one such case.
// See the companion library "oidcsessioncheck" for further details.
// The "interactively_logged_in" parameter is a boolean; it lets your app know that tokens
// are available because the user just returned from the OP (rather than reading them from browser
// storage). This may be useful in some circumstances for user-experience concerns; for example,
// you should take care to avoid looping redirections between the OP and RP by checking this value.
// Here is a sample "application" that just makes some requests to
// resource servers and outputs the response on the page.
Promise.all([
// Appropriate access tokens will be automatically included in these requests
fetch("https://default.iam.example.com/am/oauth2/userinfo").then((resp) => resp.json()),
fetch("https://default.iam.example.com/openidm/info/login").then((resp) => resp.json())
]).then((responses) => {
document.getElementById('userDetails').innerText = JSON.stringify({
"userinfo": responses[0],
"info/login": responses[1]
}, null, 4);
});
}
}).then(function () {
// In this application, we want tokens immediately. If you want to support
// any anonymous interaction, this should be delayed.
AppAuthHelper.getTokens();
});
}());
</script>
</html>