]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/oauth.js
Merge branch 'master' into notes
[rails.git] / app / assets / javascripts / oauth.js
1 //= require sha
2 //= require ohauth
3
4 $(document).ready(function () {
5   $.ajaxPrefilter(function(options, jqxhr) {
6     if (options.oauth) {
7       var ohauth = window.ohauth;
8       var url = options.url.replace(/\?$/, "");
9       var params = {
10         oauth_consumer_key: OSM.oauth_consumer_key,
11         oauth_token: OSM.oauth_token,
12         oauth_signature_method: "HMAC-SHA1",
13         oauth_timestamp: ohauth.timestamp(),
14         oauth_nonce: ohauth.nonce()
15       };
16
17       for (var name in jqxhr.data) {
18         params[name] = jqxhr.data[name];
19       }
20
21       params.oauth_signature = ohauth.signature(
22         OSM.oauth_consumer_secret,
23         OSM.oauth_token_secret,
24         ohauth.baseString(options.type, url, params)
25       );
26
27       options.headers = {
28         Authorization: "OAuth " + ohauth.authHeader(params)
29       };
30     }
31   });
32 });