-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.html
204 lines (176 loc) · 5.53 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html>
<head>
<title>osm-auth</title>
<link rel="stylesheet" type="text/css" href="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style>
body {
max-width: 400px;
margin: 40px auto;
font: normal 12px/20px "Helvetica Neue", sans-serif;
}
button {
border-radius: 5px;
background: #54af29;
border-color: #2c7505;
color: #fff;
width: 145px;
margin: 0 10px;
font-size: 25px;
text-shadow: 1px 1px -1px #2c7505;
padding: 10px;
}
button.done { background: #2c7505; }
button:hover { background: #2c7505; }
#buttons {
display: flex;
flex-flow: row nowrap;
justify-content: center;
margin-top: 20px;
}
label.single {
display: flex;
flex-flow: row nowrap;
justify-content: center;
margin-top: 20px;
}
h1 { margin: 5px 0 0 0; }
h2 { margin: 10px 0 0 0; }
p { margin: 5px 0 0 0; }
#user {
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
margin-top: 20px;
background: #ececec;
padding: 1px 10px;
border-radius: 8px;
}
#error {
display: none;
margin-top: 20px;
text-align: center;
}
#userdetail, #useravatar {
padding: 10px;
}
#avatar {
height: 80px;
width: 80px;
object-fit: cover;
border: 1px solid #ccc;
border-radius: 40px;
}
footer {
margin-top: 20px;
text-align: center;
color: #666;
}
footer img {
vertical-align: middle;
padding: 0 8px;
}
</style>
</head>
<body>
<script>var $buoop={required:{i:15,e:-4,f:-3,o:-3,s:-1,c:-3},reminder:0,noclose:true,no_permanent_hide:true,insecure:true,api:2023.07};</script>
<script src='https://browser-update.org/update.js'></script>
<div id="buttons">
<button id="authenticate">login</button>
<button id="logout">logout</button>
</div>
<label class="single">Single page: <input type="checkbox" class="single"></input></label>
<div id="error"></div>
<div id="user">
<div id="useravatar">
<img id="avatar" alt="user" src="docs/icon-avatar.svg"/>
</div>
<div id="userdetail">
<h1 id="display_name">username</h1>
<h2>User ID: <span id="userid"></span></h2>
<p>Changesets: <span id="count"></span></p>
</div>
</div>
<footer>
<a href="https://github.com/osmlab/osm-auth">
<img width="20" height="20" src="docs/GitHub-Mark-32px.png"/>osm-auth</a> is a minimal example of authenticating and interacting with the
<a href="http://www.openstreetmap.org/">OpenStreetMap API</a> over OAuth 2.0.
</footer>
<script src="dist/osm-auth.iife.js"></script>
<script>
var redirectPath = window.location.origin + window.location.pathname;
var auth = osmAuth.osmAuth({
client_id: "JWXSAzNp64sIRMStTnkhMRaMxSR964V4sFgn3KUZNTA",
scope: "read_prefs",
redirect_uri: redirectPath,
singlepage: true
});
if (window.location.search.slice(1).split('&').some(function(p) { return p.indexOf('code=') === 0; })) {
auth.authenticate(function() {
history.pushState({}, null, window.location.pathname);
update();
});
}
function done(err, result) {
if (err) {
document.getElementById("error").textContent = "Error! Try clearing your browser cache.";
document.getElementById("user").style.display = "none";
document.getElementById("error").style.display = "block";
return;
}
var user = result.getElementsByTagName("user")[0];
var changesets = result.getElementsByTagName("changesets")[0];
var avatar = result.getElementsByTagName("img")[0];
document.getElementById("display_name").textContent = user.getAttribute("display_name");
document.getElementById("avatar").alt = user.getAttribute("display_name");
document.getElementById("userid").textContent = user.getAttribute("id");
document.getElementById("count").textContent = changesets.getAttribute("count");
if (avatar) {
document.getElementById("avatar").src = avatar.getAttribute("href");
}
document.getElementById("error").style.display = "none";
document.getElementById("user").style.display = "flex";
}
document.getElementById("authenticate").onclick = function() {
var o = auth.options();
if (document.querySelector('input.single').checked) {
o.redirect_uri = redirectPath;
o.singlepage = true;
} else {
o.redirect_uri = redirectPath + "land.html"
o.singlepage = false;
}
auth.options(o);
if (!auth.bringPopupWindowToFront()) {
auth.authenticate(function() {
update();
});
}
};
function showDetails() {
auth.xhr({ method: "GET", path: "/api/0.6/user/details" }, done);
}
function hideDetails() {
document.getElementById("error").style.display = "none";
document.getElementById("user").style.display = "none";
}
document.getElementById("logout").onclick = function() {
auth.logout();
update();
};
function update() {
if (auth.authenticated()) {
document.getElementById("authenticate").className = "done";
document.getElementById("logout").className = "";
showDetails();
} else {
document.getElementById("authenticate").className = "";
document.getElementById("logout").className = "done";
hideDetails();
}
}
update();
</script>
</body>
</html>