-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
41 lines (34 loc) · 872 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
let client = new jso.JSO({
client_id: "client-id",
redirect_uri: location.href,
authorization: "https://app.simplelogin.io/oauth2/authorize",
});
// Handle redirection after user's approval
client.callback();
let token = client.checkToken();
if (token !== null) {
if (token.access_token !== undefined)
getUserData(token);
}
function login() {
client.getToken()
.then((token) => {
// user is already logged in
getUserData(token);
})
}
function reset() {
localStorage.clear();
sessionStorage.clear();
client.wipeTokens();
alert("reset successfully");
// clear all params in url
location.href = "/";
}
function getUserData(token) {
fetch('https://app.simplelogin.io/oauth2/userinfo/?access_token=' + token.access_token)
.then(response => response.json())
.then(res => {
alert(JSON.stringify(res));
})
}