-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
43 lines (33 loc) · 1011 Bytes
/
main.js
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
const providerInfo = OIDC.discover('https://app.simplelogin.io');
OIDC.setProviderInfo(providerInfo);
// OAuth2 client info. Please replace "client-id" here by your SimpleLogin OAuth2 client-id
const clientInfo = {
client_id: 'client-id',
redirect_uri: location.href
};
OIDC.storeInfo(providerInfo, clientInfo);
OIDC.setClientInfo(clientInfo);
// Restore configuration information.
OIDC.restoreInfo();
// Get Access Token
let token = OIDC.getAccessToken();
// Make userinfo request using access_token.
if (token !== null) {
getUserData(token);
}
// Make an authorization request if the user click the login button.
function login() {
OIDC.login({
scope: 'openid profile email',
response_type: 'id_token token'
});
}
function getUserData(token) {
fetch('https://app.simplelogin.io/oauth2/userinfo/?access_token=' + token)
.then(response => response.json())
.then(res => {
alert(JSON.stringify(res));
// clear all params in url
location.href = "/";
})
}