This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
forked from yui/yui3-gallery
/
gallery-oauth-debug.js
130 lines (115 loc) · 4.25 KB
/
gallery-oauth-debug.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
YUI.add('gallery-oauth', function(Y) {
/**
* This module pulls in the oAuth code from googlecode and adds a couple of helper methods
* to sign a url for standard 2-Legged oAuth
*/
var BASE = 'http://oauth.googlecode.com/svn/code/javascript/',
FILES = [ 'oauth', 'sha1' ], LOADED = 0;
if (!YUI.Env.oauthLoaded) {
Y.each(FILES, function(v) {
var url = BASE + v + '.js';
Y.Get.script(url, {
onSuccess: function() {
LOADED++;
if (LOADED === FILES.length) {
YUI.Env.oauthLoaded = true;
Y.oAuth.fire();
}
}
});
});
}
Y.namespace('oAuth');
Y.oAuth = {
fire: function() {
Y.each(Y.oAuth._items, function(fn, k) {
fn();
delete Y.oAuth._items[k];
});
},
ready: function(fn) {
if (YUI.Env.oauthLoaded) {
fn();
} else {
Y.oAuth._items.push(fn);
}
},
_items: [],
signURL: function(key, secret, url) {
var accessor = {
consumerSecret: secret,
tokenSecret: ""
},
finalStr = '',
baseStr = "",
parameterMap = "",
theSig = "",
locString = "",
item, subitem, paramList,
message = {
action: url,
method: "GET",
parameters: [
[ 'oauth_version', '1.0' ],
[ 'oauth_consumer_key', key ]
]
};
OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);
parameterMap = OAuth.getParameterMap(message);
baseStr = OAuth.decodeForm(OAuth.SignatureMethod.getBaseString(message));
if (parameterMap.parameters) {
Y.each(parameterMap.parameters, function(item) {
Y.each(item, function(subitem) {
if (subitem == "oauth_signature") {
theSig = item[1];
}
});
});
}
paramList = baseStr[2][0].split("&");
paramList.push("oauth_signature=" + encodeURIComponent(theSig));
paramList.sort(function(a,b) {
if (a[0] < b[0]) { return -1; }
if (a[0] > b[0]) { return 1; }
if (a[1] < b[1]) { return -1; }
if (a[1] > b[1]) { return 1; }
return 0;
});
Y.each(paramList, function(v, k) {
locString += paramList[k] + '&';
});
finalStr = baseStr[1][0] + '?' + locString.slice(0,locString.length - 1);
return finalStr;
}
};
if (Y.YQLRequest) {
Y.YQLRequest.prototype._send = Y.YQLRequest.prototype.send;
Y.YQLRequest.prototype.send = function() {
if (this._params.key && this._params.secret) {
if (!this._opts) {
this._opts = {};
}
this._opts.key = this._params.key;
this._opts.secret = this._params.secret;
delete this._params.key;
delete this._params.secret;
if (this._params.base) {
this._opts.base = this._params.base;
delete this._params.base;
}
if (Y.Lang.isFunction(this._callback)) {
this._callback = {
on: {
success: this._callback
}
};
}
this._callback.format = Y.bind(function(url, proxy) {
return Y.oAuth.signURL(this._opts.key, this._opts.secret, (url + 'callback=' + proxy));
}, this);
}
this._send();
};
}
}, 'gallery-2011.03.09-21-14' ,{optional:['yql'], requires:['jsonp']});