Tidy up javascript OAuth code
This commit is contained in:
parent
15be6b3ffc
commit
00a4d9fe49
1 changed files with 19 additions and 26 deletions
|
@ -1,8 +1,7 @@
|
||||||
//= require sha
|
//= require sha
|
||||||
//= require ohauth
|
//= require ohauth
|
||||||
|
|
||||||
$(document).ready(function () {
|
$.ajaxPrefilter(function(options, jqxhr) {
|
||||||
$.ajaxPrefilter(function(options, jqxhr) {
|
|
||||||
if (options.oauth) {
|
if (options.oauth) {
|
||||||
var ohauth = window.ohauth;
|
var ohauth = window.ohauth;
|
||||||
var url = options.url.replace(/\?$/, "");
|
var url = options.url.replace(/\?$/, "");
|
||||||
|
@ -14,19 +13,13 @@ $(document).ready(function () {
|
||||||
oauth_nonce: ohauth.nonce()
|
oauth_nonce: ohauth.nonce()
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var name in jqxhr.data) {
|
|
||||||
params[name] = jqxhr.data[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
params.oauth_signature = ohauth.signature(
|
params.oauth_signature = ohauth.signature(
|
||||||
OSM.oauth_consumer_secret,
|
OSM.oauth_consumer_secret,
|
||||||
OSM.oauth_token_secret,
|
OSM.oauth_token_secret,
|
||||||
ohauth.baseString(options.type, url, params)
|
ohauth.baseString(options.type, url, $.extend({}, params, jqxhr.data))
|
||||||
);
|
);
|
||||||
|
|
||||||
options.headers = {
|
options.headers = options.headers || {};
|
||||||
Authorization: "OAuth " + ohauth.authHeader(params)
|
options.headers.Authorization = "OAuth " + ohauth.authHeader(params);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue