-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
67 lines (60 loc) · 2.38 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Static Web Apps - Authentication</title>
</head>
<body>
<h1>Static Web Apps - Authentication</h1>
<div id="loginButtons"></div>
<div id="userInfo">
</div>
<code id="userDetails">
</code>
<div id="apiResult">
</div>
<script>
const providers = ["github", "twitter", "facebook", "aad", "google"];
const loginButtons = document.getElementById("loginButtons");
providers.forEach(provider => {
const button = document.createElement("button");
button.innerText = `Login with ${provider}`;
button.onclick = () => {
window.location.href = `/.auth/login/${provider}`;
};
loginButtons.appendChild(button);
});
const userInfo = document.getElementById("userInfo");
const userDetails = document.getElementById("userDetails");
fetch("/.auth/me")
.then(response => response.json())
.then(data => {
if (data.clientPrincipal) {
userInfo.innerText = `Hello ${data.clientPrincipal.userDetails}`;
userDetails.innerText = JSON.stringify(data.clientPrincipal, null, 2);
const button = document.createElement("button");
button.innerText = "Logout";
button.onclick = () => {
window.location.href = "/.auth/logout";
};
loginButtons.appendChild(button);
// invoke api/Messages and display the result
const apiResult = document.getElementById("apiResult");
const button2 = document.createElement("button");
button2.innerText = "Invoke API";
button2.onclick = () => {
fetch("/api/Messages")
.then(response => response.text())
.then(data => {
apiResult.innerText = data;
});
};
loginButtons.appendChild(button2);
} else {
userInfo.innerText = "Hello anonymous";
}
});
</script>
</body>
</html>