Tidy up javascript OAuth code
This commit is contained in:
parent
15be6b3ffc
commit
00a4d9fe49
1 changed files with 19 additions and 26 deletions
|
@ -1,32 +1,25 @@
|
||||||
//= 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(/\?$/, "");
|
var params = {
|
||||||
var params = {
|
oauth_consumer_key: OSM.oauth_consumer_key,
|
||||||
oauth_consumer_key: OSM.oauth_consumer_key,
|
oauth_token: OSM.oauth_token,
|
||||||
oauth_token: OSM.oauth_token,
|
oauth_signature_method: "HMAC-SHA1",
|
||||||
oauth_signature_method: "HMAC-SHA1",
|
oauth_timestamp: ohauth.timestamp(),
|
||||||
oauth_timestamp: ohauth.timestamp(),
|
oauth_nonce: ohauth.nonce()
|
||||||
oauth_nonce: ohauth.nonce()
|
};
|
||||||
};
|
|
||||||
|
|
||||||
for (var name in jqxhr.data) {
|
params.oauth_signature = ohauth.signature(
|
||||||
params[name] = jqxhr.data[name];
|
OSM.oauth_consumer_secret,
|
||||||
}
|
OSM.oauth_token_secret,
|
||||||
|
ohauth.baseString(options.type, url, $.extend({}, params, jqxhr.data))
|
||||||
|
);
|
||||||
|
|
||||||
params.oauth_signature = ohauth.signature(
|
options.headers = options.headers || {};
|
||||||
OSM.oauth_consumer_secret,
|
options.headers.Authorization = "OAuth " + ohauth.authHeader(params);
|
||||||
OSM.oauth_token_secret,
|
}
|
||||||
ohauth.baseString(options.type, url, params)
|
|
||||||
);
|
|
||||||
|
|
||||||
options.headers = {
|
|
||||||
Authorization: "OAuth " + ohauth.authHeader(params)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue