-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
56 lines (46 loc) · 2.08 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample OpenID App</title>
</head>
<body>
<h1>Sample OpenID App</h1>
<p>This web application uses OpenID 2.0 to verify that the user has an WG account.</p>
<button onclick="login()">Login</button>
<div id="output"></div>
<script>
const LOGIN = new URL("https://eu.wargaming.net/id/openid/").href
const REALM = new URL("/", window.location.href).href.slice(0, -1)
const RETURN_TO = new URL(".", window.location.href).href
const OUTPUT = document.getElementById("output")
function login() {
const redirectUrl = new URL(LOGIN)
redirectUrl.searchParams.set("openid.ns", "http://specs.openid.net/auth/2.0")
redirectUrl.searchParams.set("openid.mode", "checkid_setup")
redirectUrl.searchParams.set("openid.realm", REALM)
redirectUrl.searchParams.set("openid.return_to", RETURN_TO)
redirectUrl.searchParams.set("openid.claimed_id", "http://specs.openid.net/auth/2.0/identifier_select")
redirectUrl.searchParams.set("openid.identity", "http://specs.openid.net/auth/2.0/identifier_select")
window.location.assign(redirectUrl)
}
async function verifyIdentity(searchParams) {
const redirectUrl = new URL(LOGIN)
for (const [key, value] of searchParams.entries()) {
redirectUrl.searchParams.set(key, value)
}
redirectUrl.searchParams.set("openid.mode", "check_authentication")
window.location.assign(redirectUrl)
}
const searchParams = new URL(window.location.href).searchParams
const identity = searchParams.get("openid.identity")
if (identity) {
const p = document.createElement("p")
p.innerText = `Identity: ${identity}`
const button = document.createElement("button")
button.innerText = "Verify identity"
button.onclick = () => verifyIdentity(searchParams)
OUTPUT.append(p, button)
}
</script>
</body>
</html>