|
35 | 35 | verifier: empty,
|
36 | 36 |
|
37 | 37 | signatureMethod: options.signatureMethod || 'HMAC-SHA1',
|
38 |
| - timeStampFormat: options.timeStampFormat || 'ms' |
| 38 | + timeStampFormat: options.timeStampFormat || 'ms' |
39 | 39 | };
|
40 | 40 |
|
41 | 41 | this.realm = options.realm || empty;
|
42 | 42 | this.requestTokenUrl = options.requestTokenUrl || empty;
|
43 | 43 | this.authorizationUrl = options.authorizationUrl || empty;
|
44 | 44 | this.accessTokenUrl = options.accessTokenUrl || empty;
|
45 |
| - this.headerParams = {}; |
46 |
| - |
47 |
| - this.getTimeStampFormat= function () { |
48 |
| - return oauth.timeStampFormat; |
49 |
| - } |
50 |
| - |
51 |
| - this.getHeaderParams = function (options) { |
52 |
| - if (typeof options == "undefined") |
53 |
| - var options = {}; |
54 |
| - var url, headers, data, urlString, method, signature, signatureString, signatureMethod, urlString, appendQueryString, signatureData = {}, withFile = false; |
55 |
| - |
56 |
| - method = options.method || 'GET'; |
57 |
| - url = options.url ? URI(options.url) : ''; |
58 |
| - data = options.data || {}; |
59 |
| - headers = options.headers || {}; |
60 |
| - appendQueryString = options.appendQueryString ? options.appendQueryString : false; |
61 |
| - |
62 |
| - headerParams = { |
| 45 | + this.headerParams = {}; |
| 46 | + |
| 47 | + this.getTimeStampFormat= function () { |
| 48 | + return oauth.timeStampFormat; |
| 49 | + } |
| 50 | + |
| 51 | + //pulled this out of this.request to be accessible from not-closure context |
| 52 | + this.getHeaderParams = function (options) { |
| 53 | + if (typeof options == "undefined") |
| 54 | + var options = {}; |
| 55 | + var url, headers, data, urlString, method, signature, signatureString, signatureMethod, urlString, appendQueryString, signatureData = {}, withFile = false; |
| 56 | + |
| 57 | + method = options.method || 'GET'; |
| 58 | + url = options.url ? URI(options.url) : ''; |
| 59 | + data = options.data || {}; |
| 60 | + headers = options.headers || {}; |
| 61 | + appendQueryString = options.appendQueryString ? options.appendQueryString : false; |
| 62 | + |
| 63 | + headerParams = { |
63 | 64 | 'oauth_callback': oauth.callbackUrl,
|
64 | 65 | 'oauth_consumer_key': oauth.consumerKey,
|
65 | 66 | 'oauth_token': oauth.accessTokenKey,
|
|
70 | 71 | 'oauth_version': OAUTH_VERSION_1_0
|
71 | 72 | };
|
72 | 73 |
|
73 |
| - this.setHeaderParams(headerParams); |
| 74 | + this.setHeaderParams(headerParams); |
74 | 75 | signatureMethod = oauth.signatureMethod;
|
75 |
| - |
| 76 | + |
76 | 77 | // Handle GET params first
|
77 | 78 | params = url.query.toObject();
|
78 | 79 | for (i in params) {
|
|
91 | 92 | }
|
92 | 93 |
|
93 | 94 | urlString = url.scheme + '://' + url.host + url.path;
|
94 |
| - |
| 95 | + |
95 | 96 | signatureString = toSignatureBaseString(method, urlString, headerParams, signatureData);
|
96 | 97 |
|
97 | 98 | signature = OAuth.signatureMethod[signatureMethod](oauth.consumerSecret, oauth.accessTokenSecret, signatureString);
|
|
135 | 136 | query.append(i, data[i]);
|
136 | 137 | }
|
137 | 138 | }
|
138 |
| - |
139 |
| - return oauth.headerParams; |
140 |
| - } |
141 |
| - |
142 |
| - this.getHeaderString = function (url){ |
143 |
| - return toHeaderString(this.getHeaderParams({url:url})); |
144 |
| - } |
145 |
| - |
146 |
| - this.setHeaderParams = function (headerParams) { |
147 |
| - oauth.headerParams = headerParams; |
148 |
| - } |
149 |
| - |
| 139 | + |
| 140 | + return oauth.headerParams; |
| 141 | + } |
| 142 | + |
| 143 | + //transforms params to string |
| 144 | + this.getHeaderString = function (url){ |
| 145 | + return toHeaderString(this.getHeaderParams({url:url})); |
| 146 | + } |
| 147 | + |
| 148 | + this.setHeaderParams = function (headerParams) { |
| 149 | + oauth.headerParams = headerParams; |
| 150 | + } |
| 151 | + |
150 | 152 | this.getAccessToken = function () {
|
151 | 153 | return [oauth.accessTokenKey, oauth.accessTokenSecret];
|
152 | 154 | };
|
|
264 | 266 | }
|
265 | 267 | };
|
266 | 268 |
|
267 |
| - headerParams = this.getHeaderParams(options); |
| 269 | + headerParams = this.getHeaderParams(options); |
268 | 270 |
|
269 | 271 | xhr.open(method, url+'', true);
|
270 | 272 |
|
|
388 | 390 | }, failure);
|
389 | 391 | },
|
390 | 392 |
|
391 |
| - /** |
392 |
| - * Generate a timestamp for the request |
393 |
| - */ |
394 |
| - getTimestamp: function() { |
395 |
| - var oauth = this; |
396 |
| - |
397 |
| - if (oauth.getTimeStampFormat() == 's') |
398 |
| - return parseInt(+new Date() / 100000, 10); // use short form of getting a timestamp |
399 |
| - else |
400 |
| - return parseInt(+new Date() / 1000, 10); // use short form of getting a timestamp |
401 |
| - } |
| 393 | + /** |
| 394 | + * Generate a timestamp for the request |
| 395 | + * |
| 396 | + * moved function into prototype to have oauth.getTimeStampFormat() of instance avalable |
| 397 | + */ |
| 398 | + getTimestamp: function() { |
| 399 | + var oauth = this; |
| 400 | + |
| 401 | + switch (oauth.getTimeStampFormat()){ |
| 402 | + case ('ms'): |
| 403 | + return parseInt(+new Date() / 1000, 10); // use short form of getting a milliseconds-timestamp |
| 404 | + default: |
| 405 | + return parseInt(+new Date() / 100000, 10); // use short form of getting a seconds-timestamp |
| 406 | + } |
| 407 | + } |
402 | 408 | };
|
403 | 409 |
|
404 | 410 | OAuth.signatureMethod = {
|
|
0 commit comments