This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
66 lines (57 loc) · 2.45 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
<!DOCTYPE html>
<head>
<title>OSM OAuth</title>
</head>
<body>
<script type='text/javascript' src='ohauth.js'></script>
<script>
// in the popup response
var search = document.location.search;
if (search !== '') {
var oauth_token = ohauth.stringQs(search.slice(1));
var token_secret = document.cookie.match(/ohauth_token_secret=([^;]+)/);
alert('got:\noauth_token = ' + oauth_token.oauth_token + '\noauth_token_secret = ' + token_secret[1]);
window.close();
}
</script>
<p>Click the button to authenticate against
the <a href='http://api06.dev.openstreetmap.org'>development OSM server</a>:
</p>
<button id='authenticate'>Authenticate</button>
<script>
var host = 'http://api06.dev.openstreetmap.org',
oauth_secret = 'aMnOOCwExO2XYtRVWJ1bI9QOdqh1cay2UgpbhA6p';
var o = {
oauth_consumer_key: 'zwQZFivccHkLs3a8Rq5CoS412fE5aPCXDw9DZj7R',
oauth_signature_method: 'HMAC-SHA1'
};
document.getElementById('authenticate').onclick = function() {
// Create a 600x550 popup window in the center of the screen
var w = 600,
h = 550,
settings = [
['width', w], ['height', h],
['left', screen.width / 2 - w / 2],
['top', screen.height / 2 - h / 2]].map(function(x) {
return x.join('=');
}).join(','),
popup = window.open('about:blank', 'oauth_window', settings);
o.oauth_timestamp = ohauth.timestamp();
o.oauth_nonce = ohauth.nonce();
var url = host + '/oauth/request_token';
o.oauth_signature = ohauth.signature(oauth_secret, '', ohauth.baseString('POST', url, o));
ohauth.xhr('POST', url, o, null, {}, function(err, xhr) {
if (err) { alert(err); return; }
var token = ohauth.stringQs(xhr.response);
document.cookie = 'ohauth_token_secret=' + token.oauth_token_secret;
var at = host + '/oauth/authorize?';
alert('sending:\noauth_token_secret = ' + token.oauth_token_secret);
popup.location = at + ohauth.qsString({
oauth_token: token.oauth_token,
oauth_callback: location.href
});
});
};
</script>
</body>
</HTML>