forked from achimschloss/fedcm-rp-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
234 lines (215 loc) · 8.81 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!--
Copyright 2023 European netID Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Portions of this code are derived from the FedCM Demo
https://fedcm-rp-demo.glitch.me/, licensed under the Apache License,
Version 2.0 by 2019 Google Inc. Copyright 2019
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>FedCM RP Demo</title>
<meta name="description" content="FedCM RP Demo" />
<link id="favicon" rel="icon"
href="https://cdn.glitch.me/94838ffe-241b-4a67-a9e0-290bfe34c351%2Fbank.png?v=1639111444422" type="image/x-icon" />
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/styles-bundle.css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://unpkg.com/material-components-web@7.0.0/dist/material-components-web.min.css" />
<script src="components-bundle.js" type="module"></script>
<meta name="nonce" content="{{nonce}}" />
<meta http-equiv="origin-trial" content="{{ot_token}}" />
</head>
<body class="mdc-typography">
<mwc-top-app-bar-fixed>
<span slot="title">FedCM RP Demo</span>
<mwc-icon-button id="home" icon="home" slot="actionItems"></mwc-icon-button>
<mwc-icon-button id="settings" icon="settings" slot="actionItems"></mwc-icon-button>
<mwc-icon-button id="code" icon="code" slot="actionItems"></mwc-icon-button>
</mwc-top-app-bar-fixed>
<mwc-linear-progress id="progress"></mwc-linear-progress>
<main class="content">
<h2 class="center">Welcome to FedCM RP Demo!</h2>
<p id="unsupported" class="warning hidden">
Your browser does not support FedCM. Try on Chrome for Android with a
flag chrome://flags/#fedcm.
</p>
<div id="settings-tab" class="center hidden">
<h2>Settings</h2>
<!-- Your existing settings UI goes here -->
<div class="config-container">
<div class="config-item">
<label for="mode-input">Mode:</label>
<mwc-select id="mode-input" outlined>
<mwc-list-item value="pageload" {{#if (eq config.mode 'pageload' )}}selected{{/if}}>PageLoad</mwc-list-item>
<mwc-list-item value="onclick" {{#if (eq config.mode 'onclick' )}}selected{{/if}}>On-Click</mwc-list-item>
<mwc-list-item value="button" {{#if (eq config.mode 'button' )}}selected{{/if}}>Button
(Experimental)</mwc-list-item>
</mwc-select>
</div>
<div class="config-container">
<div class="config-item">
<label for="mediation-input">Mediation:</label>
<mwc-select id="mediation-input" outlined>
<mwc-list-item value="silent" {{#if (eq config.mediation 'silent'
)}}selected{{/if}}>Silent</mwc-list-item>
<mwc-list-item value="optional" {{#if (eq config.mediation 'optional'
)}}selected{{/if}}>Optional</mwc-list-item>
<mwc-list-item value="conditional" {{#if (eq config.mediation 'conditional'
)}}selected{{/if}}>Conditional</mwc-list-item>
<mwc-list-item value="required" {{#if (eq config.mediation 'required'
)}}selected{{/if}}>Required</mwc-list-item>
</mwc-select>
</div>
</div>
<div class="config-item">
<label for="scope-input">Scope:</label>
<mwc-textfield outlined id="scope-input" label="Scope" placeholder="email,name,picture"
value="{{config.scope}}"></mwc-textfield>
</div>
<div class="config-item">
<label for="context-input">Context:</label>
<mwc-textfield id="context-input" placeholder="use" label="Context" value="{{config.context}}" outlined>
</mwc-textfield>
</div>
<div class="config-item">
<label for="user-info-toggle">User Info:</label>
<mwc-switch id="user-info-toggle" {{#if config.userInfoEnabled}}selected{{/if}}>
></mwc-switch>
</div>
</div>
<mwc-button id="config-save" raised>Save</mwc-button>
</div>
<div id="main-sections">
<div id="profile" class="center"></div>
<div id="login" class="center">
<p class="instructions">
If you don't see a sign-in dialog, you need to sign-in on the IDP
first. The IDP might also need to "wake-up" again given its a
testing setup its not always running. Visiting the IDP will help in
this case too
</p>
{{#if (eq config.mode 'onclick')}}
<mwc-button id="signOnButton" raised>Sign In</mwc-button>
{{/if}}
{{#if (eq config.mode 'button')}}
<mwc-button id="signOnButton" raised>Sign In</mwc-button>
{{/if}}
<!-- Add a button to link to the sign-in page -->
{{#each config.idpConfig}}
<a href="{{getOrigin this.configURL}}" id="idp-link-{{@index}}">
<mwc-button raised>Visit IDP {{@index}}</mwc-button>
</a>
{{/each}}
</div>
{{#if config.userInfoEnabled}}
<div id="personalizedButton" class="iframe-container"></div>
{{/if}}
</div>
</main>
<script type="module">
import {
$,
toast,
loading,
_fetch,
getCredential,
handleConfigSave,
switchTab,
createIframes,
} from "./client.js";
$("#home").addEventListener("click", () => location.reload());
$("#settings").addEventListener("click", () => switchTab("settings-tab"));
$("#code").addEventListener("click", (e) => {
location.href = "https://glitch.com/edit/#!/furtive-candy-cauliflower";
});
$("#config-save").addEventListener("click", handleConfigSave);
let config;
// initalize from backend and start getCredential if set to onPageload
async function initialize() {
const configResponse = await fetch("/config");
config = await configResponse.json();
const idpConfig = config.idpConfig
if ("IdentityCredential" in window) {
if (config && config.mode === "pageload") {
signIn();
} else {
$("#signOnButton").addEventListener("click", async function () {
await signIn();
});
}
} else {
$("#unsupported").classList.remove("hidden");
}
if (config && config.userInfoEnabled) {
createIframes("personalizedButton", config.idpConfig);
}
}
initialize().catch((err) => console.error(err));
const signIn = async () => {
try {
try {
const credential = await getCredential(config);
const nonce = $('meta[name="nonce"]').content;
const token = credential.token; //await credential.login({ nonce });
console.log(token);
await _fetch("/verify", { token });
/*
Reload the page in case no error occurs (i.e. user was signed in successfully)
Note this is a simplistic example to finish the login flow. We do a very basic ID Token
verification with a fixed secret (see server.js). If this would be a OPEN_ID based IDP (outside of FedCM)
the usual mechanisms would be applied for ID Token verfication, or the token here might be a
authorization code and could for example reload the /auth callback of the RP with the code
*/
location.reload();
} catch (e) {
console.error(e);
toast(e.message);
}
} catch (e) {
console.error(e);
toast(e.message);
}
};
const signout = (account_id) => async () => {
try {
loading.start();
toast("You are signed out. Redirecting in 3.0 sec.");
setTimeout(() => {
location.href = "/signout";
}, 3000);
} catch (e) {
loading.stop();
console.error(e);
toast(e.message);
}
};
const unregister = (username) => async () => {
try {
loading.start();
const credential = await getCredential();
await credential.revoke(username);
toast("Your account is revoked. Redirecting in 3.0 sec.");
setTimeout(() => {
location.href = "/signout";
}, 3000);
} catch (e) {
loading.stop();
console.error(e);
toast(e.message);
}
};
</script>
<mwc-snackbar id="snackbar"></mwc-snackbar>
</body>
</html>