-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
index.html
75 lines (72 loc) · 2.79 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
<!doctype html>
<html lang="en">
<head>
<title>Login with OAuth2 / OpenId Connect</title>
<style>
body {
margin: 50px 50px;
}
a {
display: block;
line-height: 40px;
}
</style>
</head>
<body>
<h1>Login with OAuth2 / OpenId Connect</h1>
<div class="container">
<div id="login" style="display:block">
<a href="/oauth2/authorization/github">Login with Github</a>
<a href="/oauth2/authorization/google">Login with Google</a>
<a href="/oauth2/authorization/facebook">Login with Facebook</a>
<a href="/oauth2/authorization/okta">Login with Okta</a>
<a href="/oauth2/authorization/linkedin">Login with LinkedIn</a>
<a href="/oauth2/authorization/discord">Login with Discord</a>
</div>
<div id="welcome" style="display:none">
Welcome <span id="name"></span> | <button onClick="logout()">Logout</button>
</div>
</div>
<script>
fetch('/user')
.then((response) => {
if (response.ok) {
return response.json();
} else {
throw new Error('Something went wrong');
}
})
.then((responseJson) => {
document.getElementById('name').innerText = responseJson.username;
document.getElementById('login').style.display = 'none';
document.getElementById('welcome').style.display = 'block';
})
.catch((error) => {
console.error('Error: ', error);
});
function logout() {
fetch('/logout', {
method: 'POST',
headers: {
'X-XSRF-TOKEN': getCookie('XSRF-TOKEN')
}
})
.then((response) => {
if (response.ok) {
document.getElementById('login').style.display = 'block';
document.getElementById('welcome').style.display = 'none';
} else {
throw new Error('Something went wrong');
}
})
.catch((error) => {
console.error('Error: ', error);
});
}
function getCookie(name) {
var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
return v ? v[2] : null;
}
</script>
</body>
</html>