-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
104 lines (96 loc) · 4.74 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
<!DOCTYPE html>
<head>
<title>OSM OAuth</title>
</head>
<body>
<button id='authenticate'>Authenticate</button>
<button disabled=true id='add-point'>Add Random Point</button>
<iframe width='800' height='600' id='ifr'></iframe>
<script type="text/javascript" src="sha.js"></script>
<script type="text/javascript" src="ohauth.js"></script>
<script>
var ifr = document.getElementById('ifr');
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() {
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(xhr) {
var token = ohauth.stringQs(xhr.response);
document.cookie = 'ohauth_token_secret=' + token.oauth_token_secret;
var at = host + '/oauth/authorize?';
ifr.src = at + ohauth.qsString({
oauth_token: token.oauth_token,
oauth_callback: location.href
});
});
};
var change = '<osm>' +
'<changeset>' +
'<tag k="created_by" v="iD0"/>' +
'<tag k="comment" v="Just adding some streetnames"/>' +
'<\/changeset>' +
'<\/osm>';
var node = '<osmChange version="0.3" generator="Osmosis">' +
'<create>' +
'<node version="1" changeset="{changeset}" id="-1" lat="-33.9133118622908" lon="151.117335519304">' +
'<tag k="created_by" v="iD"/>' +
'<\/node>' +
'<\/create>' +
'<\/osmChange>'
ifr.onload = function() {
if (ifr.contentWindow.location.search) {
var search = ifr.contentWindow.location.search;
var oauth_token = ohauth.stringQs(search.slice(1));
o.oauth_timestamp = ohauth.timestamp();
o.oauth_nonce = ohauth.nonce();
o.oauth_token = oauth_token.oauth_token;
var url = host + '/oauth/access_token';
var token_secret = document.cookie.match(/ohauth_token_secret=([^;]+)/);
if (!token_secret) return console.error('Required token not found');
o.oauth_signature = ohauth.signature(oauth_secret, token_secret[1],
ohauth.baseString('POST', url, o));
ohauth.xhr('POST', url, o, null, {}, function(xhr) {
var access_token = ohauth.stringQs(xhr.response);
o.oauth_token = access_token.oauth_token;
o.oauth_timestamp = ohauth.timestamp();
o.oauth_nonce = ohauth.nonce();
token_secret = access_token.oauth_token_secret;
var url = host + '/api/0.6/changeset/create';
o.oauth_signature = ohauth.signature(oauth_secret, token_secret,
ohauth.baseString('PUT', url, o));
ohauth.xhr('PUT', url, o, change, { header: { 'Content-Type': 'text/xml' } },
function(xhr) {
var changeset_id = xhr.response;
var url = host + '/api/0.6/changeset/' + changeset_id + '/upload'
o.oauth_timestamp = ohauth.timestamp();
o.oauth_nonce = ohauth.nonce();
o.oauth_signature = ohauth.signature(oauth_secret, token_secret,
ohauth.baseString('POST', url, o));
node = node.replace('{changeset}', changeset_id);
ohauth.xhr('POST', url, o, node, { header: { 'Content-Type': 'text/xml' } },
function(xhr) {
var url = host + '/api/0.6/changeset/' + changeset_id + '/close';
o.oauth_timestamp = ohauth.timestamp();
o.oauth_nonce = ohauth.nonce();
o.oauth_signature = ohauth.signature(oauth_secret, token_secret,
ohauth.baseString('PUT', url, o));
ohauth.xhr('PUT', url, o, '', { header: { 'Content-Type': 'text/xml' } },
function(xhr) {
console.log(arguments);
});
});
});
});
}
}
</script>
</body>
</HTML>