forked from enumatech/metamask-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
63 lines (56 loc) · 1.86 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
<html>
<head>
<title>OAuth2 client</title>
<meta charset="UTF-8"/>
<meta name="copyright" content="Enuma Technologies Limited"/>
<meta name="author" content="Lionello Lunesu"/>
</head>
<body>
<h1>OAuth2 client</h1>
<button id="authorize">Login</button>
<button id="logout">Logout</button>
<div id="target"></div>
<script type="text/javascript" src="query.js"></script>
<script type="text/javascript">
(function(){
function render(str) {
document.getElementById("target").innerText = str;
}
function setCookie(token) {
document.cookie = "token=" + (token ? token : ";expires=Thu, 01 Jan 1970 00:00:01 GMT") + "; path=/";
}
function logout(e) {
setCookie();
render("You've been logged out!");
}
var response = parseQuery(window.location.hash);
if (response.error) {
render(response.error_description || response.error);
setCookie();
}
else if (response.access_token && response.token_type === "bearer" && response.state === "login") {
render("You've been authenticated!");
setCookie(response.access_token);
}
else if (document.cookie && /\btoken=e/.test(document.cookie)) {
render("You're still authenticated!");
}
window.location.hash = "";
function authorize(e) {
// Redirect to /authorize endpoint
window.location.href = "authorize.html?"
+ makeQuery({
client_id: "self",
response_type: "token",
redirect_uri: window.location,
state: "login",
//scope: "scope",
//response_mode: "query"
});
}
document.getElementById("authorize").addEventListener("click", authorize);
document.getElementById("logout").addEventListener("click", logout);
})();
</script>
</body>
</html>