oauthiojs-rails 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +2 -0
- data/lib/oauthiojs/oauthiojs-rails.rb +6 -0
- data/lib/oauthiojs/rails/version.rb +5 -0
- data/oauthiojs-rails.gemspec +26 -0
- data/vendor/assets/javascripts/oauth.js +1217 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6efb5042744c91054c496a661818f8e339c6ba03
|
4
|
+
data.tar.gz: 3f4621e6d3b7072e5f0159fc756c7e135c092793
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bfb5592a60b5bcca6d0990a42d5ef8905cf2550440a2cd3bf3e9c667cc91605ab6873ebe75b57813de89fc9c5334b1f74517788468a2167590a3e15ff8101a8c
|
7
|
+
data.tar.gz: 651bd59634ac4b703518e1a6b1e3f89f563f619ebe41b60cf755babd321b5cf0650c7926b7962fe0e7e9c90205f4c88fa7d53becab59a97027bc17d9ba11a69e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jonathan Rowlands
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# oauthiojs-rails
|
2
|
+
|
3
|
+
oauthiojs-rails wraps the [oauth.js](https://oauth.io/) library in a rails engine for simple
|
4
|
+
use with the asset pipeline provided by rails 3.1. The gem includes the development (non-minified)
|
5
|
+
source for ease of exploration. The asset pipeline will minify in production.
|
6
|
+
|
7
|
+
oauth.js is "a javascript OAuth library allows you to integrate 100+ providers really easily in your web app,
|
8
|
+
without worrying about each provider's OAuth specific implementation."
|
9
|
+
Please see the [documentation](https://oauth.io/docs/api-reference/client/javascript) for details.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Add the following to your gemfile:
|
14
|
+
|
15
|
+
gem 'oauthiojs-rails'
|
16
|
+
|
17
|
+
Add the following directive to your Javascript manifest file (application.js):
|
18
|
+
|
19
|
+
//= require oauthio
|
20
|
+
|
21
|
+
|
22
|
+
## Versioning
|
23
|
+
|
24
|
+
oauthiojs-rails 0.2.4 == oauth.js 0.2.4
|
25
|
+
|
26
|
+
Every attempt is made to mirror the currently shipping oauth.js version number wherever possible.
|
27
|
+
The major, minor, and patch version numbers will always represent the oauth.js version. Should a gem
|
28
|
+
bug be discovered, a 4th version identifier will be added and incremented.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oauthiojs/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oauthiojs-rails"
|
8
|
+
spec.version = Oauthiojs::Rails::VERSION
|
9
|
+
spec.authors = ["Jonathan Rowlands"]
|
10
|
+
spec.email = ["jonrowlands83@gmail.com"]
|
11
|
+
spec.summary = "The oauth.js JavaScript library ready to play with Rails."
|
12
|
+
spec.description = <<-EOF
|
13
|
+
OAuth.io allows you to integrate 100+ providers really easily in your web app, without worrying about each
|
14
|
+
provider's OAuth specific implementation.
|
15
|
+
EOF
|
16
|
+
|
17
|
+
spec.homepage = "https://oauth.io"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0")
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "railties", "~> 3.1"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
@@ -0,0 +1,1217 @@
|
|
1
|
+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2
|
+
module.exports = {
|
3
|
+
oauthd_url: "https://oauth.io",
|
4
|
+
oauthd_api: "https://oauth.io/api",
|
5
|
+
version: "web-0.2.4",
|
6
|
+
options: {}
|
7
|
+
};
|
8
|
+
|
9
|
+
},{}],2:[function(require,module,exports){
|
10
|
+
"use strict";
|
11
|
+
var Url, cache, config, cookies, sha1;
|
12
|
+
|
13
|
+
config = require("../config");
|
14
|
+
|
15
|
+
cookies = require("../tools/cookies");
|
16
|
+
|
17
|
+
cache = require("../tools/cache");
|
18
|
+
|
19
|
+
Url = require("../tools/url");
|
20
|
+
|
21
|
+
sha1 = require("../tools/sha1");
|
22
|
+
|
23
|
+
module.exports = function(window, document, jQuery, navigator) {
|
24
|
+
var $, client_states, oauth_result, oauthio, parse_urlfragment, providers_api, providers_cb, providers_desc;
|
25
|
+
$ = jQuery;
|
26
|
+
Url = Url(document);
|
27
|
+
cookies.init(config, document);
|
28
|
+
cache.init(cookies, config);
|
29
|
+
oauthio = {
|
30
|
+
request: {}
|
31
|
+
};
|
32
|
+
providers_desc = {};
|
33
|
+
providers_cb = {};
|
34
|
+
providers_api = {
|
35
|
+
execProvidersCb: function(provider, e, r) {
|
36
|
+
var cbs, i;
|
37
|
+
if (providers_cb[provider]) {
|
38
|
+
cbs = providers_cb[provider];
|
39
|
+
delete providers_cb[provider];
|
40
|
+
for (i in cbs) {
|
41
|
+
cbs[i](e, r);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
},
|
45
|
+
getDescription: function(provider, opts, callback) {
|
46
|
+
opts = opts || {};
|
47
|
+
if (typeof providers_desc[provider] === "object") {
|
48
|
+
return callback(null, providers_desc[provider]);
|
49
|
+
}
|
50
|
+
if (!providers_desc[provider]) {
|
51
|
+
providers_api.fetchDescription(provider);
|
52
|
+
}
|
53
|
+
if (!opts.wait) {
|
54
|
+
return callback(null, {});
|
55
|
+
}
|
56
|
+
providers_cb[provider] = providers_cb[provider] || [];
|
57
|
+
providers_cb[provider].push(callback);
|
58
|
+
}
|
59
|
+
};
|
60
|
+
config.oauthd_base = Url.getAbsUrl(config.oauthd_url).match(/^.{2,5}:\/\/[^/]+/)[0];
|
61
|
+
client_states = [];
|
62
|
+
oauth_result = void 0;
|
63
|
+
(parse_urlfragment = function() {
|
64
|
+
var cookie_state, results;
|
65
|
+
results = /[\\#&]oauthio=([^&]*)/.exec(document.location.hash);
|
66
|
+
if (results) {
|
67
|
+
document.location.hash = document.location.hash.replace(/&?oauthio=[^&]*/, "");
|
68
|
+
oauth_result = decodeURIComponent(results[1].replace(/\+/g, " "));
|
69
|
+
cookie_state = cookies.readCookie("oauthio_state");
|
70
|
+
if (cookie_state) {
|
71
|
+
client_states.push(cookie_state);
|
72
|
+
cookies.eraseCookie("oauthio_state");
|
73
|
+
}
|
74
|
+
}
|
75
|
+
})();
|
76
|
+
window.location_operations = {
|
77
|
+
reload: function() {
|
78
|
+
return document.location.reload();
|
79
|
+
},
|
80
|
+
getHash: function() {
|
81
|
+
return document.location.hash;
|
82
|
+
},
|
83
|
+
setHash: function(newHash) {
|
84
|
+
return document.location.hash = newHash;
|
85
|
+
},
|
86
|
+
changeHref: function(newLocation) {
|
87
|
+
return document.location.href = newLocation;
|
88
|
+
}
|
89
|
+
};
|
90
|
+
return function(exports) {
|
91
|
+
var delayedFunctions, delayfn, e, _preloadcalls;
|
92
|
+
delayedFunctions = function($) {
|
93
|
+
oauthio.request = require("./oauthio_requests")($, config, client_states, cache, providers_api);
|
94
|
+
providers_api.fetchDescription = function(provider) {
|
95
|
+
if (providers_desc[provider]) {
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
providers_desc[provider] = true;
|
99
|
+
$.ajax({
|
100
|
+
url: config.oauthd_api + "/providers/" + provider,
|
101
|
+
data: {
|
102
|
+
extend: true
|
103
|
+
},
|
104
|
+
dataType: "json"
|
105
|
+
}).done(function(data) {
|
106
|
+
providers_desc[provider] = data.data;
|
107
|
+
providers_api.execProvidersCb(provider, null, data.data);
|
108
|
+
}).always(function() {
|
109
|
+
if (typeof providers_desc[provider] !== "object") {
|
110
|
+
delete providers_desc[provider];
|
111
|
+
providers_api.execProvidersCb(provider, new Error("Unable to fetch request description"));
|
112
|
+
}
|
113
|
+
});
|
114
|
+
};
|
115
|
+
};
|
116
|
+
if (exports.OAuth == null) {
|
117
|
+
exports.OAuth = {
|
118
|
+
initialize: function(public_key, options) {
|
119
|
+
var i;
|
120
|
+
config.key = public_key;
|
121
|
+
if (options) {
|
122
|
+
for (i in options) {
|
123
|
+
config.options[i] = options[i];
|
124
|
+
}
|
125
|
+
}
|
126
|
+
},
|
127
|
+
setOAuthdURL: function(url) {
|
128
|
+
config.oauthd_url = url;
|
129
|
+
config.oauthd_base = Url.getAbsUrl(config.oauthd_url).match(/^.{2,5}:\/\/[^/]+/)[0];
|
130
|
+
},
|
131
|
+
getVersion: function() {
|
132
|
+
return config.version;
|
133
|
+
},
|
134
|
+
create: function(provider, tokens, request) {
|
135
|
+
var i, make_res, make_res_endpoint, res;
|
136
|
+
if (!tokens) {
|
137
|
+
return cache.tryCache(exports.OAuth, provider, true);
|
138
|
+
}
|
139
|
+
if (typeof request !== "object") {
|
140
|
+
providers_api.fetchDescription(provider);
|
141
|
+
}
|
142
|
+
make_res = function(method) {
|
143
|
+
return oauthio.request.mkHttp(provider, tokens, request, method);
|
144
|
+
};
|
145
|
+
make_res_endpoint = function(method, url) {
|
146
|
+
return oauthio.request.mkHttpEndpoint(provider, tokens, request, method, url);
|
147
|
+
};
|
148
|
+
res = {};
|
149
|
+
for (i in tokens) {
|
150
|
+
res[i] = tokens[i];
|
151
|
+
}
|
152
|
+
res.get = make_res("GET");
|
153
|
+
res.post = make_res("POST");
|
154
|
+
res.put = make_res("PUT");
|
155
|
+
res.patch = make_res("PATCH");
|
156
|
+
res.del = make_res("DELETE");
|
157
|
+
res.me = oauthio.request.mkHttpMe(provider, tokens, request, "GET");
|
158
|
+
return res;
|
159
|
+
},
|
160
|
+
popup: function(provider, opts, callback) {
|
161
|
+
var defer, frm, getMessage, gotmessage, interval, res, url, wnd, wndTimeout, wnd_options, wnd_settings, _ref;
|
162
|
+
gotmessage = false;
|
163
|
+
getMessage = function(e) {
|
164
|
+
if (e.origin !== config.oauthd_base) {
|
165
|
+
return;
|
166
|
+
}
|
167
|
+
try {
|
168
|
+
wnd.close();
|
169
|
+
} catch (_error) {}
|
170
|
+
opts.data = e.data;
|
171
|
+
oauthio.request.sendCallback(opts, defer);
|
172
|
+
return gotmessage = true;
|
173
|
+
};
|
174
|
+
wnd = void 0;
|
175
|
+
frm = void 0;
|
176
|
+
wndTimeout = void 0;
|
177
|
+
defer = (_ref = window.jQuery) != null ? _ref.Deferred() : void 0;
|
178
|
+
opts = opts || {};
|
179
|
+
if (!config.key) {
|
180
|
+
if (defer != null) {
|
181
|
+
defer.reject(new Error("OAuth object must be initialized"));
|
182
|
+
}
|
183
|
+
if (callback == null) {
|
184
|
+
return defer.promise();
|
185
|
+
} else {
|
186
|
+
return callback(new Error("OAuth object must be initialized"));
|
187
|
+
}
|
188
|
+
}
|
189
|
+
if (arguments.length === 2 && typeof opts === 'function') {
|
190
|
+
callback = opts;
|
191
|
+
opts = {};
|
192
|
+
}
|
193
|
+
if (cache.cacheEnabled(opts.cache)) {
|
194
|
+
res = cache.tryCache(exports.OAuth, provider, opts.cache);
|
195
|
+
if (res) {
|
196
|
+
if (defer != null) {
|
197
|
+
defer.resolve(res);
|
198
|
+
}
|
199
|
+
if (callback) {
|
200
|
+
return callback(null, res);
|
201
|
+
} else {
|
202
|
+
return defer.promise();
|
203
|
+
}
|
204
|
+
}
|
205
|
+
}
|
206
|
+
if (!opts.state) {
|
207
|
+
opts.state = sha1.create_hash();
|
208
|
+
opts.state_type = "client";
|
209
|
+
}
|
210
|
+
client_states.push(opts.state);
|
211
|
+
url = config.oauthd_url + "/auth/" + provider + "?k=" + config.key;
|
212
|
+
url += "&d=" + encodeURIComponent(Url.getAbsUrl("/"));
|
213
|
+
if (opts) {
|
214
|
+
url += "&opts=" + encodeURIComponent(JSON.stringify(opts));
|
215
|
+
}
|
216
|
+
if (opts.wnd_settings) {
|
217
|
+
wnd_settings = opts.wnd_settings;
|
218
|
+
delete opts.wnd_settings;
|
219
|
+
} else {
|
220
|
+
wnd_settings = {
|
221
|
+
width: Math.floor(window.outerWidth * 0.8),
|
222
|
+
height: Math.floor(window.outerHeight * 0.5)
|
223
|
+
};
|
224
|
+
}
|
225
|
+
if (wnd_settings.height == null) {
|
226
|
+
wnd_settings.height = (wnd_settings.height < 350 ? 350 : void 0);
|
227
|
+
}
|
228
|
+
if (wnd_settings.width == null) {
|
229
|
+
wnd_settings.width = (wnd_settings.width < 800 ? 800 : void 0);
|
230
|
+
}
|
231
|
+
if (wnd_settings.left == null) {
|
232
|
+
wnd_settings.left = window.screenX + (window.outerWidth - wnd_settings.width) / 2;
|
233
|
+
}
|
234
|
+
if (wnd_settings.top == null) {
|
235
|
+
wnd_settings.top = window.screenY + (window.outerHeight - wnd_settings.height) / 8;
|
236
|
+
}
|
237
|
+
wnd_options = "width=" + wnd_settings.width + ",height=" + wnd_settings.height;
|
238
|
+
wnd_options += ",toolbar=0,scrollbars=1,status=1,resizable=1,location=1,menuBar=0";
|
239
|
+
wnd_options += ",left=" + wnd_settings.left + ",top=" + wnd_settings.top;
|
240
|
+
opts = {
|
241
|
+
provider: provider,
|
242
|
+
cache: opts.cache
|
243
|
+
};
|
244
|
+
opts.callback = function(e, r) {
|
245
|
+
if (window.removeEventListener) {
|
246
|
+
window.removeEventListener("message", getMessage, false);
|
247
|
+
} else if (window.detachEvent) {
|
248
|
+
window.detachEvent("onmessage", getMessage);
|
249
|
+
} else {
|
250
|
+
if (document.detachEvent) {
|
251
|
+
document.detachEvent("onmessage", getMessage);
|
252
|
+
}
|
253
|
+
}
|
254
|
+
opts.callback = function() {};
|
255
|
+
if (wndTimeout) {
|
256
|
+
clearTimeout(wndTimeout);
|
257
|
+
wndTimeout = undefined;
|
258
|
+
}
|
259
|
+
if (callback) {
|
260
|
+
return callback(e, r);
|
261
|
+
} else {
|
262
|
+
return undefined;
|
263
|
+
}
|
264
|
+
};
|
265
|
+
if (window.attachEvent) {
|
266
|
+
window.attachEvent("onmessage", getMessage);
|
267
|
+
} else if (document.attachEvent) {
|
268
|
+
document.attachEvent("onmessage", getMessage);
|
269
|
+
} else {
|
270
|
+
if (window.addEventListener) {
|
271
|
+
window.addEventListener("message", getMessage, false);
|
272
|
+
}
|
273
|
+
}
|
274
|
+
if (typeof chrome !== "undefined" && chrome.runtime && chrome.runtime.onMessageExternal) {
|
275
|
+
chrome.runtime.onMessageExternal.addListener(function(request, sender, sendResponse) {
|
276
|
+
request.origin = sender.url.match(/^.{2,5}:\/\/[^/]+/)[0];
|
277
|
+
if (defer != null) {
|
278
|
+
defer.resolve();
|
279
|
+
}
|
280
|
+
return getMessage(request);
|
281
|
+
});
|
282
|
+
}
|
283
|
+
if (!frm && (navigator.userAgent.indexOf("MSIE") !== -1 || navigator.appVersion.indexOf("Trident/") > 0)) {
|
284
|
+
frm = document.createElement("iframe");
|
285
|
+
frm.src = config.oauthd_url + "/auth/iframe?d=" + encodeURIComponent(Url.getAbsUrl("/"));
|
286
|
+
frm.width = 0;
|
287
|
+
frm.height = 0;
|
288
|
+
frm.frameBorder = 0;
|
289
|
+
frm.style.visibility = "hidden";
|
290
|
+
document.body.appendChild(frm);
|
291
|
+
}
|
292
|
+
wndTimeout = setTimeout(function() {
|
293
|
+
if (defer != null) {
|
294
|
+
defer.reject(new Error("Authorization timed out"));
|
295
|
+
}
|
296
|
+
if (opts.callback && typeof opts.callback === "function") {
|
297
|
+
opts.callback(new Error("Authorization timed out"));
|
298
|
+
}
|
299
|
+
try {
|
300
|
+
wnd.close();
|
301
|
+
} catch (_error) {}
|
302
|
+
}, 1200 * 1000);
|
303
|
+
wnd = window.open(url, "Authorization", wnd_options);
|
304
|
+
if (wnd) {
|
305
|
+
wnd.focus();
|
306
|
+
interval = window.setInterval(function() {
|
307
|
+
if (wnd === null || wnd.closed) {
|
308
|
+
window.clearInterval(interval);
|
309
|
+
if (!gotmessage) {
|
310
|
+
if (defer != null) {
|
311
|
+
defer.reject(new Error("The popup was closed"));
|
312
|
+
}
|
313
|
+
if (opts.callback && typeof opts.callback === "function") {
|
314
|
+
return opts.callback(new Error("The popup was closed"));
|
315
|
+
}
|
316
|
+
}
|
317
|
+
}
|
318
|
+
}, 500);
|
319
|
+
} else {
|
320
|
+
if (defer != null) {
|
321
|
+
defer.reject(new Error("Could not open a popup"));
|
322
|
+
}
|
323
|
+
if (opts.callback && typeof opts.callback === "function") {
|
324
|
+
opts.callback(new Error("Could not open a popup"));
|
325
|
+
}
|
326
|
+
}
|
327
|
+
return defer != null ? defer.promise() : void 0;
|
328
|
+
},
|
329
|
+
redirect: function(provider, opts, url) {
|
330
|
+
var redirect_uri, res;
|
331
|
+
if (arguments.length === 2) {
|
332
|
+
url = opts;
|
333
|
+
opts = {};
|
334
|
+
}
|
335
|
+
if (cache.cacheEnabled(opts.cache)) {
|
336
|
+
res = cache.tryCache(exports.OAuth, provider, opts.cache);
|
337
|
+
if (res) {
|
338
|
+
url = Url.getAbsUrl(url) + (url.indexOf("#") === -1 ? "#" : "&") + "oauthio=cache";
|
339
|
+
window.location_operations.changeHref(url);
|
340
|
+
window.location_operations.reload();
|
341
|
+
return;
|
342
|
+
}
|
343
|
+
}
|
344
|
+
if (!opts.state) {
|
345
|
+
opts.state = sha1.create_hash();
|
346
|
+
opts.state_type = "client";
|
347
|
+
}
|
348
|
+
cookies.createCookie("oauthio_state", opts.state);
|
349
|
+
redirect_uri = encodeURIComponent(Url.getAbsUrl(url));
|
350
|
+
url = config.oauthd_url + "/auth/" + provider + "?k=" + config.key;
|
351
|
+
url += "&redirect_uri=" + redirect_uri;
|
352
|
+
if (opts) {
|
353
|
+
url += "&opts=" + encodeURIComponent(JSON.stringify(opts));
|
354
|
+
}
|
355
|
+
window.location_operations.changeHref(url);
|
356
|
+
},
|
357
|
+
callback: function(provider, opts, callback) {
|
358
|
+
var defer, res, _ref;
|
359
|
+
defer = (_ref = window.jQuery) != null ? _ref.Deferred() : void 0;
|
360
|
+
if (arguments.length === 1 && typeof provider === "function") {
|
361
|
+
callback = provider;
|
362
|
+
provider = undefined;
|
363
|
+
opts = {};
|
364
|
+
}
|
365
|
+
if (arguments.length === 1 && typeof provider === "string") {
|
366
|
+
opts = {};
|
367
|
+
}
|
368
|
+
if (arguments.length === 2 && typeof opts === "function") {
|
369
|
+
callback = opts;
|
370
|
+
opts = {};
|
371
|
+
}
|
372
|
+
if (cache.cacheEnabled(opts.cache) || oauth_result === "cache") {
|
373
|
+
res = cache.tryCache(exports.OAuth, provider, opts.cache);
|
374
|
+
if (oauth_result === "cache" && (typeof provider !== "string" || !provider)) {
|
375
|
+
if (defer != null) {
|
376
|
+
defer.reject(new Error("You must set a provider when using the cache"));
|
377
|
+
}
|
378
|
+
if (callback) {
|
379
|
+
return callback(new Error("You must set a provider when using the cache"));
|
380
|
+
} else {
|
381
|
+
return defer != null ? defer.promise() : void 0;
|
382
|
+
}
|
383
|
+
}
|
384
|
+
if (res) {
|
385
|
+
if (callback) {
|
386
|
+
if (res) {
|
387
|
+
return callback(null, res);
|
388
|
+
}
|
389
|
+
} else {
|
390
|
+
if (defer != null) {
|
391
|
+
defer.resolve(res);
|
392
|
+
}
|
393
|
+
return defer != null ? defer.promise() : void 0;
|
394
|
+
}
|
395
|
+
}
|
396
|
+
}
|
397
|
+
if (!oauth_result) {
|
398
|
+
return;
|
399
|
+
}
|
400
|
+
oauthio.request.sendCallback({
|
401
|
+
data: oauth_result,
|
402
|
+
provider: provider,
|
403
|
+
cache: opts.cache,
|
404
|
+
callback: callback
|
405
|
+
}, defer);
|
406
|
+
return defer != null ? defer.promise() : void 0;
|
407
|
+
},
|
408
|
+
clearCache: function(provider) {
|
409
|
+
cookies.eraseCookie("oauthio_provider_" + provider);
|
410
|
+
},
|
411
|
+
http_me: function(opts) {
|
412
|
+
if (oauthio.request.http_me) {
|
413
|
+
oauthio.request.http_me(opts);
|
414
|
+
}
|
415
|
+
},
|
416
|
+
http: function(opts) {
|
417
|
+
if (oauthio.request.http) {
|
418
|
+
oauthio.request.http(opts);
|
419
|
+
}
|
420
|
+
}
|
421
|
+
};
|
422
|
+
if (typeof window.jQuery === "undefined") {
|
423
|
+
_preloadcalls = [];
|
424
|
+
delayfn = void 0;
|
425
|
+
if (typeof chrome !== "undefined" && chrome.extension) {
|
426
|
+
delayfn = function() {
|
427
|
+
return function() {
|
428
|
+
throw new Error("Please include jQuery before oauth.js");
|
429
|
+
};
|
430
|
+
};
|
431
|
+
} else {
|
432
|
+
e = document.createElement("script");
|
433
|
+
e.src = "//code.jquery.com/jquery.min.js";
|
434
|
+
e.type = "text/javascript";
|
435
|
+
e.onload = function() {
|
436
|
+
var i;
|
437
|
+
delayedFunctions(window.jQuery);
|
438
|
+
for (i in _preloadcalls) {
|
439
|
+
_preloadcalls[i].fn.apply(null, _preloadcalls[i].args);
|
440
|
+
}
|
441
|
+
};
|
442
|
+
document.getElementsByTagName("head")[0].appendChild(e);
|
443
|
+
delayfn = function(f) {
|
444
|
+
return function() {
|
445
|
+
var arg, args_copy;
|
446
|
+
args_copy = [];
|
447
|
+
for (arg in arguments) {
|
448
|
+
args_copy[arg] = arguments[arg];
|
449
|
+
}
|
450
|
+
_preloadcalls.push({
|
451
|
+
fn: f,
|
452
|
+
args: args_copy
|
453
|
+
});
|
454
|
+
};
|
455
|
+
};
|
456
|
+
}
|
457
|
+
oauthio.request.http = delayfn(function() {
|
458
|
+
oauthio.request.http.apply(exports.OAuth, arguments);
|
459
|
+
});
|
460
|
+
providers_api.fetchDescription = delayfn(function() {
|
461
|
+
providers_api.fetchDescription.apply(providers_api, arguments);
|
462
|
+
});
|
463
|
+
oauthio.request = require("./oauthio_requests")(window.jQuery, config, client_states, cache, providers_api);
|
464
|
+
} else {
|
465
|
+
delayedFunctions(window.jQuery);
|
466
|
+
}
|
467
|
+
}
|
468
|
+
};
|
469
|
+
};
|
470
|
+
|
471
|
+
},{"../config":1,"../tools/cache":5,"../tools/cookies":6,"../tools/sha1":7,"../tools/url":8,"./oauthio_requests":3}],3:[function(require,module,exports){
|
472
|
+
var Url,
|
473
|
+
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
474
|
+
|
475
|
+
Url = require('../tools/url')();
|
476
|
+
|
477
|
+
module.exports = function($, config, client_states, cache, providers_api) {
|
478
|
+
return {
|
479
|
+
http: function(opts) {
|
480
|
+
var defer, desc_opts, doRequest, i, options;
|
481
|
+
doRequest = function() {
|
482
|
+
var i, k, qs, request;
|
483
|
+
request = options.oauthio.request || {};
|
484
|
+
if (!request.cors) {
|
485
|
+
options.url = encodeURIComponent(options.url);
|
486
|
+
if (options.url[0] !== "/") {
|
487
|
+
options.url = "/" + options.url;
|
488
|
+
}
|
489
|
+
options.url = config.oauthd_url + "/request/" + options.oauthio.provider + options.url;
|
490
|
+
options.headers = options.headers || {};
|
491
|
+
options.headers.oauthio = "k=" + config.key;
|
492
|
+
if (options.oauthio.tokens.oauth_token && options.oauthio.tokens.oauth_token_secret) {
|
493
|
+
options.headers.oauthio += "&oauthv=1";
|
494
|
+
}
|
495
|
+
for (k in options.oauthio.tokens) {
|
496
|
+
options.headers.oauthio += "&" + encodeURIComponent(k) + "=" + encodeURIComponent(options.oauthio.tokens[k]);
|
497
|
+
}
|
498
|
+
delete options.oauthio;
|
499
|
+
return $.ajax(options);
|
500
|
+
}
|
501
|
+
if (options.oauthio.tokens) {
|
502
|
+
if (options.oauthio.tokens.access_token) {
|
503
|
+
options.oauthio.tokens.token = options.oauthio.tokens.access_token;
|
504
|
+
}
|
505
|
+
if (!options.url.match(/^[a-z]{2,16}:\/\//)) {
|
506
|
+
if (options.url[0] !== "/") {
|
507
|
+
options.url = "/" + options.url;
|
508
|
+
}
|
509
|
+
options.url = request.url + options.url;
|
510
|
+
}
|
511
|
+
options.url = Url.replaceParam(options.url, options.oauthio.tokens, request.parameters);
|
512
|
+
if (request.query) {
|
513
|
+
qs = [];
|
514
|
+
for (i in request.query) {
|
515
|
+
qs.push(encodeURIComponent(i) + "=" + encodeURIComponent(Url.replaceParam(request.query[i], options.oauthio.tokens, request.parameters)));
|
516
|
+
}
|
517
|
+
if (__indexOf.call(options.url, "?") >= 0) {
|
518
|
+
options.url += "&" + qs;
|
519
|
+
} else {
|
520
|
+
options.url += "?" + qs;
|
521
|
+
}
|
522
|
+
}
|
523
|
+
if (request.headers) {
|
524
|
+
options.headers = options.headers || {};
|
525
|
+
for (i in request.headers) {
|
526
|
+
options.headers[i] = Url.replaceParam(request.headers[i], options.oauthio.tokens, request.parameters);
|
527
|
+
}
|
528
|
+
}
|
529
|
+
delete options.oauthio;
|
530
|
+
return $.ajax(options);
|
531
|
+
}
|
532
|
+
};
|
533
|
+
options = {};
|
534
|
+
i = void 0;
|
535
|
+
for (i in opts) {
|
536
|
+
options[i] = opts[i];
|
537
|
+
}
|
538
|
+
if (!options.oauthio.request || options.oauthio.request === true) {
|
539
|
+
desc_opts = {
|
540
|
+
wait: !!options.oauthio.request
|
541
|
+
};
|
542
|
+
defer = $ != null ? $.Deferred() : void 0;
|
543
|
+
providers_api.getDescription(options.oauthio.provider, desc_opts, function(e, desc) {
|
544
|
+
if (e) {
|
545
|
+
return defer != null ? defer.reject(e) : void 0;
|
546
|
+
}
|
547
|
+
if (options.oauthio.tokens.oauth_token && options.oauthio.tokens.oauth_token_secret) {
|
548
|
+
options.oauthio.request = desc.oauth1 && desc.oauth1.request;
|
549
|
+
} else {
|
550
|
+
options.oauthio.request = desc.oauth2 && desc.oauth2.request;
|
551
|
+
}
|
552
|
+
if (defer != null) {
|
553
|
+
defer.resolve();
|
554
|
+
}
|
555
|
+
});
|
556
|
+
return defer != null ? defer.then(doRequest) : void 0;
|
557
|
+
} else {
|
558
|
+
return doRequest();
|
559
|
+
}
|
560
|
+
},
|
561
|
+
http_me: function(opts) {
|
562
|
+
var defer, desc_opts, doRequest, k, options;
|
563
|
+
doRequest = function() {
|
564
|
+
var defer, k, promise, request;
|
565
|
+
defer = $ != null ? $.Deferred() : void 0;
|
566
|
+
request = options.oauthio.request || {};
|
567
|
+
options.url = config.oauthd_url + "/auth/" + options.oauthio.provider + "/me";
|
568
|
+
options.headers = options.headers || {};
|
569
|
+
options.headers.oauthio = "k=" + config.key;
|
570
|
+
if (options.oauthio.tokens.oauth_token && options.oauthio.tokens.oauth_token_secret) {
|
571
|
+
options.headers.oauthio += "&oauthv=1";
|
572
|
+
}
|
573
|
+
for (k in options.oauthio.tokens) {
|
574
|
+
options.headers.oauthio += "&" + encodeURIComponent(k) + "=" + encodeURIComponent(options.oauthio.tokens[k]);
|
575
|
+
}
|
576
|
+
delete options.oauthio;
|
577
|
+
promise = $.ajax(options);
|
578
|
+
$.when(promise).done(function(data) {
|
579
|
+
if (defer != null) {
|
580
|
+
defer.resolve(data.data);
|
581
|
+
}
|
582
|
+
}).fail(function(data) {
|
583
|
+
if (data.responseJSON) {
|
584
|
+
if (defer != null) {
|
585
|
+
defer.reject(data.responseJSON.data);
|
586
|
+
}
|
587
|
+
} else {
|
588
|
+
if (defer != null) {
|
589
|
+
defer.reject(new Error("An error occured while trying to access the resource"));
|
590
|
+
}
|
591
|
+
}
|
592
|
+
});
|
593
|
+
return defer != null ? defer.promise() : void 0;
|
594
|
+
};
|
595
|
+
options = {};
|
596
|
+
for (k in opts) {
|
597
|
+
options[k] = opts[k];
|
598
|
+
}
|
599
|
+
if (!options.oauthio.request || options.oauthio.request === true) {
|
600
|
+
desc_opts = {
|
601
|
+
wait: !!options.oauthio.request
|
602
|
+
};
|
603
|
+
defer = $ != null ? $.Deferred() : void 0;
|
604
|
+
providers_api.getDescription(options.oauthio.provider, desc_opts, function(e, desc) {
|
605
|
+
if (e) {
|
606
|
+
return defer != null ? defer.reject(e) : void 0;
|
607
|
+
}
|
608
|
+
if (options.oauthio.tokens.oauth_token && options.oauthio.tokens.oauth_token_secret) {
|
609
|
+
options.oauthio.request = desc.oauth1 && desc.oauth1.request;
|
610
|
+
} else {
|
611
|
+
options.oauthio.request = desc.oauth2 && desc.oauth2.request;
|
612
|
+
}
|
613
|
+
if (defer != null) {
|
614
|
+
defer.resolve();
|
615
|
+
}
|
616
|
+
});
|
617
|
+
return defer != null ? defer.then(doRequest) : void 0;
|
618
|
+
} else {
|
619
|
+
return doRequest();
|
620
|
+
}
|
621
|
+
},
|
622
|
+
mkHttp: function(provider, tokens, request, method) {
|
623
|
+
var base;
|
624
|
+
base = this;
|
625
|
+
return function(opts, opts2) {
|
626
|
+
var i, options;
|
627
|
+
options = {};
|
628
|
+
if (typeof opts === "string") {
|
629
|
+
if (typeof opts2 === "object") {
|
630
|
+
for (i in opts2) {
|
631
|
+
options[i] = opts2[i];
|
632
|
+
}
|
633
|
+
}
|
634
|
+
options.url = opts;
|
635
|
+
} else if (typeof opts === "object") {
|
636
|
+
for (i in opts) {
|
637
|
+
options[i] = opts[i];
|
638
|
+
}
|
639
|
+
}
|
640
|
+
options.type = options.type || method;
|
641
|
+
options.oauthio = {
|
642
|
+
provider: provider,
|
643
|
+
tokens: tokens,
|
644
|
+
request: request
|
645
|
+
};
|
646
|
+
return base.http(options);
|
647
|
+
};
|
648
|
+
},
|
649
|
+
mkHttpMe: function(provider, tokens, request, method) {
|
650
|
+
var base;
|
651
|
+
base = this;
|
652
|
+
return function(filter) {
|
653
|
+
var options;
|
654
|
+
options = {};
|
655
|
+
options.type = options.type || method;
|
656
|
+
options.oauthio = {
|
657
|
+
provider: provider,
|
658
|
+
tokens: tokens,
|
659
|
+
request: request
|
660
|
+
};
|
661
|
+
options.data = options.data || {};
|
662
|
+
options.data.filter = (filter ? filter.join(",") : undefined);
|
663
|
+
return base.http_me(options);
|
664
|
+
};
|
665
|
+
},
|
666
|
+
sendCallback: function(opts, defer) {
|
667
|
+
var base, data, e, err, i, k, make_res, request, res, tokens, v;
|
668
|
+
base = this;
|
669
|
+
data = void 0;
|
670
|
+
err = void 0;
|
671
|
+
try {
|
672
|
+
data = JSON.parse(opts.data);
|
673
|
+
} catch (_error) {
|
674
|
+
e = _error;
|
675
|
+
if (defer != null) {
|
676
|
+
defer.reject(new Error("Error while parsing result"));
|
677
|
+
}
|
678
|
+
return opts.callback(new Error("Error while parsing result"));
|
679
|
+
}
|
680
|
+
if (!data || !data.provider) {
|
681
|
+
return;
|
682
|
+
}
|
683
|
+
if (opts.provider && data.provider.toLowerCase() !== opts.provider.toLowerCase()) {
|
684
|
+
err = new Error("Returned provider name does not match asked provider");
|
685
|
+
if (defer != null) {
|
686
|
+
defer.reject(err);
|
687
|
+
}
|
688
|
+
if (opts.callback && typeof opts.callback === "function") {
|
689
|
+
return opts.callback(err);
|
690
|
+
} else {
|
691
|
+
return;
|
692
|
+
}
|
693
|
+
}
|
694
|
+
if (data.status === "error" || data.status === "fail") {
|
695
|
+
err = new Error(data.message);
|
696
|
+
err.body = data.data;
|
697
|
+
if (defer != null) {
|
698
|
+
defer.reject(err);
|
699
|
+
}
|
700
|
+
if (opts.callback && typeof opts.callback === "function") {
|
701
|
+
return opts.callback(err);
|
702
|
+
} else {
|
703
|
+
return;
|
704
|
+
}
|
705
|
+
}
|
706
|
+
if (data.status !== "success" || !data.data) {
|
707
|
+
err = new Error();
|
708
|
+
err.body = data.data;
|
709
|
+
if (defer != null) {
|
710
|
+
defer.reject(err);
|
711
|
+
}
|
712
|
+
if (opts.callback && typeof opts.callback === "function") {
|
713
|
+
return opts.callback(err);
|
714
|
+
} else {
|
715
|
+
return;
|
716
|
+
}
|
717
|
+
}
|
718
|
+
data.state = data.state.replace(/\s+/g, "");
|
719
|
+
for (k in client_states) {
|
720
|
+
v = client_states[k];
|
721
|
+
client_states[k] = v.replace(/\s+/g, "");
|
722
|
+
}
|
723
|
+
if (!data.state || client_states.indexOf(data.state) === -1) {
|
724
|
+
if (defer != null) {
|
725
|
+
defer.reject(new Error("State is not matching"));
|
726
|
+
}
|
727
|
+
if (opts.callback && typeof opts.callback === "function") {
|
728
|
+
return opts.callback(new Error("State is not matching"));
|
729
|
+
} else {
|
730
|
+
return;
|
731
|
+
}
|
732
|
+
}
|
733
|
+
if (!opts.provider) {
|
734
|
+
data.data.provider = data.provider;
|
735
|
+
}
|
736
|
+
res = data.data;
|
737
|
+
if (cache.cacheEnabled(opts.cache) && res) {
|
738
|
+
cache.storeCache(data.provider, res);
|
739
|
+
}
|
740
|
+
request = res.request;
|
741
|
+
delete res.request;
|
742
|
+
tokens = void 0;
|
743
|
+
if (res.access_token) {
|
744
|
+
tokens = {
|
745
|
+
access_token: res.access_token
|
746
|
+
};
|
747
|
+
} else if (res.oauth_token && res.oauth_token_secret) {
|
748
|
+
tokens = {
|
749
|
+
oauth_token: res.oauth_token,
|
750
|
+
oauth_token_secret: res.oauth_token_secret
|
751
|
+
};
|
752
|
+
}
|
753
|
+
if (!request) {
|
754
|
+
if (defer != null) {
|
755
|
+
defer.resolve(res);
|
756
|
+
}
|
757
|
+
if (opts.callback && typeof opts.callback === "function") {
|
758
|
+
return opts.callback(null, res);
|
759
|
+
} else {
|
760
|
+
return;
|
761
|
+
}
|
762
|
+
}
|
763
|
+
if (request.required) {
|
764
|
+
for (i in request.required) {
|
765
|
+
tokens[request.required[i]] = res[request.required[i]];
|
766
|
+
}
|
767
|
+
}
|
768
|
+
make_res = function(method) {
|
769
|
+
return base.mkHttp(data.provider, tokens, request, method);
|
770
|
+
};
|
771
|
+
res.get = make_res("GET");
|
772
|
+
res.post = make_res("POST");
|
773
|
+
res.put = make_res("PUT");
|
774
|
+
res.patch = make_res("PATCH");
|
775
|
+
res.del = make_res("DELETE");
|
776
|
+
res.me = base.mkHttpMe(data.provider, tokens, request, "GET");
|
777
|
+
if (defer != null) {
|
778
|
+
defer.resolve(res);
|
779
|
+
}
|
780
|
+
if (opts.callback && typeof opts.callback === "function") {
|
781
|
+
return opts.callback(null, res);
|
782
|
+
} else {
|
783
|
+
|
784
|
+
}
|
785
|
+
}
|
786
|
+
};
|
787
|
+
};
|
788
|
+
|
789
|
+
},{"../tools/url":8}],4:[function(require,module,exports){
|
790
|
+
var OAuth_creator, jquery;
|
791
|
+
|
792
|
+
if (typeof jQuery !== "undefined" && jQuery !== null) {
|
793
|
+
jquery = jQuery;
|
794
|
+
} else {
|
795
|
+
jquery = void 0;
|
796
|
+
}
|
797
|
+
|
798
|
+
OAuth_creator = require('./lib/oauth')(window, document, jquery, navigator);
|
799
|
+
|
800
|
+
OAuth_creator(window || this);
|
801
|
+
|
802
|
+
},{"./lib/oauth":2}],5:[function(require,module,exports){
|
803
|
+
module.exports = {
|
804
|
+
init: function(cookies_module, config) {
|
805
|
+
this.config = config;
|
806
|
+
return this.cookies = cookies_module;
|
807
|
+
},
|
808
|
+
tryCache: function(OAuth, provider, cache) {
|
809
|
+
var e, i, res;
|
810
|
+
if (this.cacheEnabled(cache)) {
|
811
|
+
cache = this.cookies.readCookie("oauthio_provider_" + provider);
|
812
|
+
if (!cache) {
|
813
|
+
return false;
|
814
|
+
}
|
815
|
+
cache = decodeURIComponent(cache);
|
816
|
+
}
|
817
|
+
if (typeof cache === "string") {
|
818
|
+
try {
|
819
|
+
cache = JSON.parse(cache);
|
820
|
+
} catch (_error) {
|
821
|
+
e = _error;
|
822
|
+
return false;
|
823
|
+
}
|
824
|
+
}
|
825
|
+
if (typeof cache === "object") {
|
826
|
+
res = {};
|
827
|
+
for (i in cache) {
|
828
|
+
if (i !== "request" && typeof cache[i] !== "function") {
|
829
|
+
res[i] = cache[i];
|
830
|
+
}
|
831
|
+
}
|
832
|
+
return OAuth.create(provider, res, cache.request);
|
833
|
+
}
|
834
|
+
return false;
|
835
|
+
},
|
836
|
+
storeCache: function(provider, cache) {
|
837
|
+
this.cookies.createCookie("oauthio_provider_" + provider, encodeURIComponent(JSON.stringify(cache)), cache.expires_in - 10 || 3600);
|
838
|
+
},
|
839
|
+
cacheEnabled: function(cache) {
|
840
|
+
if (typeof cache === "undefined") {
|
841
|
+
return this.config.options.cache;
|
842
|
+
}
|
843
|
+
return cache;
|
844
|
+
}
|
845
|
+
};
|
846
|
+
|
847
|
+
},{}],6:[function(require,module,exports){
|
848
|
+
|
849
|
+
/* istanbul ignore next */
|
850
|
+
module.exports = {
|
851
|
+
init: function(config, document) {
|
852
|
+
this.config = config;
|
853
|
+
return this.document = document;
|
854
|
+
},
|
855
|
+
createCookie: function(name, value, expires) {
|
856
|
+
var date;
|
857
|
+
this.eraseCookie(name);
|
858
|
+
date = new Date();
|
859
|
+
date.setTime(date.getTime() + (expires || 1200) * 1000);
|
860
|
+
expires = "; expires=" + date.toGMTString();
|
861
|
+
this.document.cookie = name + "=" + value + expires + "; path=/";
|
862
|
+
},
|
863
|
+
readCookie: function(name) {
|
864
|
+
var c, ca, i, nameEQ;
|
865
|
+
nameEQ = name + "=";
|
866
|
+
ca = this.document.cookie.split(";");
|
867
|
+
i = 0;
|
868
|
+
while (i < ca.length) {
|
869
|
+
c = ca[i];
|
870
|
+
while (c.charAt(0) === " ") {
|
871
|
+
c = c.substring(1, c.length);
|
872
|
+
}
|
873
|
+
if (c.indexOf(nameEQ) === 0) {
|
874
|
+
return c.substring(nameEQ.length, c.length);
|
875
|
+
}
|
876
|
+
i++;
|
877
|
+
}
|
878
|
+
return null;
|
879
|
+
},
|
880
|
+
eraseCookie: function(name) {
|
881
|
+
var date;
|
882
|
+
date = new Date();
|
883
|
+
date.setTime(date.getTime() - 86400000);
|
884
|
+
this.document.cookie = name + "=; expires=" + date.toGMTString() + "; path=/";
|
885
|
+
}
|
886
|
+
};
|
887
|
+
|
888
|
+
},{}],7:[function(require,module,exports){
|
889
|
+
var b64pad, hexcase;
|
890
|
+
|
891
|
+
hexcase = 0;
|
892
|
+
|
893
|
+
b64pad = "";
|
894
|
+
|
895
|
+
|
896
|
+
/* istanbul ignore next */
|
897
|
+
|
898
|
+
module.exports = {
|
899
|
+
hex_sha1: function(s) {
|
900
|
+
return this.rstr2hex(this.rstr_sha1(this.str2rstr_utf8(s)));
|
901
|
+
},
|
902
|
+
b64_sha1: function(s) {
|
903
|
+
return this.rstr2b64(this.rstr_sha1(this.str2rstr_utf8(s)));
|
904
|
+
},
|
905
|
+
any_sha1: function(s, e) {
|
906
|
+
return this.rstr2any(this.rstr_sha1(this.str2rstr_utf8(s)), e);
|
907
|
+
},
|
908
|
+
hex_hmac_sha1: function(k, d) {
|
909
|
+
return this.rstr2hex(this.rstr_hmac_sha1(this.str2rstr_utf8(k), this.str2rstr_utf8(d)));
|
910
|
+
},
|
911
|
+
b64_hmac_sha1: function(k, d) {
|
912
|
+
return this.rstr2b64(this.rstr_hmac_sha1(this.str2rstr_utf8(k), this.str2rstr_utf8(d)));
|
913
|
+
},
|
914
|
+
any_hmac_sha1: function(k, d, e) {
|
915
|
+
return this.rstr2any(this.rstr_hmac_sha1(this.str2rstr_utf8(k), this.str2rstr_utf8(d)), e);
|
916
|
+
},
|
917
|
+
sha1_vm_test: function() {
|
918
|
+
return thishex_sha1("abc").toLowerCase() === "a9993e364706816aba3e25717850c26c9cd0d89d";
|
919
|
+
},
|
920
|
+
rstr_sha1: function(s) {
|
921
|
+
return this.binb2rstr(this.binb_sha1(this.rstr2binb(s), s.length * 8));
|
922
|
+
},
|
923
|
+
rstr_hmac_sha1: function(key, data) {
|
924
|
+
var bkey, hash, i, ipad, opad;
|
925
|
+
bkey = this.rstr2binb(key);
|
926
|
+
if (bkey.length > 16) {
|
927
|
+
bkey = this.binb_sha1(bkey, key.length * 8);
|
928
|
+
}
|
929
|
+
ipad = Array(16);
|
930
|
+
opad = Array(16);
|
931
|
+
i = 0;
|
932
|
+
while (i < 16) {
|
933
|
+
ipad[i] = bkey[i] ^ 0x36363636;
|
934
|
+
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
935
|
+
i++;
|
936
|
+
}
|
937
|
+
hash = this.binb_sha1(ipad.concat(this.rstr2binb(data)), 512 + data.length * 8);
|
938
|
+
return this.binb2rstr(this.binb_sha1(opad.concat(hash), 512 + 160));
|
939
|
+
},
|
940
|
+
rstr2hex: function(input) {
|
941
|
+
var e, hex_tab, i, output, x;
|
942
|
+
try {
|
943
|
+
hexcase;
|
944
|
+
} catch (_error) {
|
945
|
+
e = _error;
|
946
|
+
hexcase = 0;
|
947
|
+
}
|
948
|
+
hex_tab = (hexcase ? "0123456789ABCDEF" : "0123456789abcdef");
|
949
|
+
output = "";
|
950
|
+
x = void 0;
|
951
|
+
i = 0;
|
952
|
+
while (i < input.length) {
|
953
|
+
x = input.charCodeAt(i);
|
954
|
+
output += hex_tab.charAt((x >>> 4) & 0x0F) + hex_tab.charAt(x & 0x0F);
|
955
|
+
i++;
|
956
|
+
}
|
957
|
+
return output;
|
958
|
+
},
|
959
|
+
rstr2b64: function(input) {
|
960
|
+
var e, i, j, len, output, tab, triplet;
|
961
|
+
try {
|
962
|
+
b64pad;
|
963
|
+
} catch (_error) {
|
964
|
+
e = _error;
|
965
|
+
b64pad = "";
|
966
|
+
}
|
967
|
+
tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
968
|
+
output = "";
|
969
|
+
len = input.length;
|
970
|
+
i = 0;
|
971
|
+
while (i < len) {
|
972
|
+
triplet = (input.charCodeAt(i) << 16) | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) | (i + 2 < len ? input.charCodeAt(i + 2) : 0);
|
973
|
+
j = 0;
|
974
|
+
while (j < 4) {
|
975
|
+
if (i * 8 + j * 6 > input.length * 8) {
|
976
|
+
output += b64pad;
|
977
|
+
} else {
|
978
|
+
output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);
|
979
|
+
}
|
980
|
+
j++;
|
981
|
+
}
|
982
|
+
i += 3;
|
983
|
+
}
|
984
|
+
return output;
|
985
|
+
},
|
986
|
+
rstr2any: function(input, encoding) {
|
987
|
+
var dividend, divisor, full_length, i, output, q, quotient, remainders, x;
|
988
|
+
divisor = encoding.length;
|
989
|
+
remainders = Array();
|
990
|
+
i = void 0;
|
991
|
+
q = void 0;
|
992
|
+
x = void 0;
|
993
|
+
quotient = void 0;
|
994
|
+
dividend = Array(Math.ceil(input.length / 2));
|
995
|
+
i = 0;
|
996
|
+
while (i < dividend.length) {
|
997
|
+
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
|
998
|
+
i++;
|
999
|
+
}
|
1000
|
+
while (dividend.length > 0) {
|
1001
|
+
quotient = Array();
|
1002
|
+
x = 0;
|
1003
|
+
i = 0;
|
1004
|
+
while (i < dividend.length) {
|
1005
|
+
x = (x << 16) + dividend[i];
|
1006
|
+
q = Math.floor(x / divisor);
|
1007
|
+
x -= q * divisor;
|
1008
|
+
if (quotient.length > 0 || q > 0) {
|
1009
|
+
quotient[quotient.length] = q;
|
1010
|
+
}
|
1011
|
+
i++;
|
1012
|
+
}
|
1013
|
+
remainders[remainders.length] = x;
|
1014
|
+
dividend = quotient;
|
1015
|
+
}
|
1016
|
+
output = "";
|
1017
|
+
i = remainders.length - 1;
|
1018
|
+
while (i >= 0) {
|
1019
|
+
output += encoding.charAt(remainders[i]);
|
1020
|
+
i--;
|
1021
|
+
}
|
1022
|
+
full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
|
1023
|
+
i = output.length;
|
1024
|
+
while (i < full_length) {
|
1025
|
+
output = encoding[0] + output;
|
1026
|
+
i++;
|
1027
|
+
}
|
1028
|
+
return output;
|
1029
|
+
},
|
1030
|
+
str2rstr_utf8: function(input) {
|
1031
|
+
var i, output, x, y;
|
1032
|
+
output = "";
|
1033
|
+
i = -1;
|
1034
|
+
x = void 0;
|
1035
|
+
y = void 0;
|
1036
|
+
while (++i < input.length) {
|
1037
|
+
x = input.charCodeAt(i);
|
1038
|
+
y = (i + 1 < input.length ? input.charCodeAt(i + 1) : 0);
|
1039
|
+
if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
|
1040
|
+
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
|
1041
|
+
i++;
|
1042
|
+
}
|
1043
|
+
if (x <= 0x7F) {
|
1044
|
+
output += String.fromCharCode(x);
|
1045
|
+
} else if (x <= 0x7FF) {
|
1046
|
+
output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F), 0x80 | (x & 0x3F));
|
1047
|
+
} else if (x <= 0xFFFF) {
|
1048
|
+
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 0x80 | ((x >>> 6) & 0x3F), 0x80 | (x & 0x3F));
|
1049
|
+
} else {
|
1050
|
+
if (x <= 0x1FFFFF) {
|
1051
|
+
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 0x80 | ((x >>> 12) & 0x3F), 0x80 | ((x >>> 6) & 0x3F), 0x80 | (x & 0x3F));
|
1052
|
+
}
|
1053
|
+
}
|
1054
|
+
}
|
1055
|
+
return output;
|
1056
|
+
},
|
1057
|
+
str2rstr_utf16le: function(input) {
|
1058
|
+
var i, output;
|
1059
|
+
output = "";
|
1060
|
+
i = 0;
|
1061
|
+
while (i < input.length) {
|
1062
|
+
output += String.fromCharCode(input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF);
|
1063
|
+
i++;
|
1064
|
+
}
|
1065
|
+
return output;
|
1066
|
+
},
|
1067
|
+
str2rstr_utf16be: function(input) {
|
1068
|
+
var i, output;
|
1069
|
+
output = "";
|
1070
|
+
i = 0;
|
1071
|
+
while (i < input.length) {
|
1072
|
+
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF);
|
1073
|
+
i++;
|
1074
|
+
}
|
1075
|
+
return output;
|
1076
|
+
},
|
1077
|
+
rstr2binb: function(input) {
|
1078
|
+
var i, output;
|
1079
|
+
output = Array(input.length >> 2);
|
1080
|
+
i = 0;
|
1081
|
+
while (i < output.length) {
|
1082
|
+
output[i] = 0;
|
1083
|
+
i++;
|
1084
|
+
}
|
1085
|
+
i = 0;
|
1086
|
+
while (i < input.length * 8) {
|
1087
|
+
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
|
1088
|
+
i += 8;
|
1089
|
+
}
|
1090
|
+
return output;
|
1091
|
+
},
|
1092
|
+
binb2rstr: function(input) {
|
1093
|
+
var i, output;
|
1094
|
+
output = "";
|
1095
|
+
i = 0;
|
1096
|
+
while (i < input.length * 32) {
|
1097
|
+
output += String.fromCharCode((input[i >> 5] >>> (24 - i % 32)) & 0xFF);
|
1098
|
+
i += 8;
|
1099
|
+
}
|
1100
|
+
return output;
|
1101
|
+
},
|
1102
|
+
binb_sha1: function(x, len) {
|
1103
|
+
var a, b, c, d, e, i, j, olda, oldb, oldc, oldd, olde, t, w;
|
1104
|
+
x[len >> 5] |= 0x80 << (24 - len % 32);
|
1105
|
+
x[((len + 64 >> 9) << 4) + 15] = len;
|
1106
|
+
w = Array(80);
|
1107
|
+
a = 1732584193;
|
1108
|
+
b = -271733879;
|
1109
|
+
c = -1732584194;
|
1110
|
+
d = 271733878;
|
1111
|
+
e = -1009589776;
|
1112
|
+
i = 0;
|
1113
|
+
while (i < x.length) {
|
1114
|
+
olda = a;
|
1115
|
+
oldb = b;
|
1116
|
+
oldc = c;
|
1117
|
+
oldd = d;
|
1118
|
+
olde = e;
|
1119
|
+
j = 0;
|
1120
|
+
while (j < 80) {
|
1121
|
+
if (j < 16) {
|
1122
|
+
w[j] = x[i + j];
|
1123
|
+
} else {
|
1124
|
+
w[j] = this.bit_rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
|
1125
|
+
}
|
1126
|
+
t = this.safe_add(this.safe_add(this.bit_rol(a, 5), this.sha1_ft(j, b, c, d)), this.safe_add(this.safe_add(e, w[j]), this.sha1_kt(j)));
|
1127
|
+
e = d;
|
1128
|
+
d = c;
|
1129
|
+
c = this.bit_rol(b, 30);
|
1130
|
+
b = a;
|
1131
|
+
a = t;
|
1132
|
+
j++;
|
1133
|
+
}
|
1134
|
+
a = this.safe_add(a, olda);
|
1135
|
+
b = this.safe_add(b, oldb);
|
1136
|
+
c = this.safe_add(c, oldc);
|
1137
|
+
d = this.safe_add(d, oldd);
|
1138
|
+
e = this.safe_add(e, olde);
|
1139
|
+
i += 16;
|
1140
|
+
}
|
1141
|
+
return Array(a, b, c, d, e);
|
1142
|
+
},
|
1143
|
+
sha1_ft: function(t, b, c, d) {
|
1144
|
+
if (t < 20) {
|
1145
|
+
return (b & c) | ((~b) & d);
|
1146
|
+
}
|
1147
|
+
if (t < 40) {
|
1148
|
+
return b ^ c ^ d;
|
1149
|
+
}
|
1150
|
+
if (t < 60) {
|
1151
|
+
return (b & c) | (b & d) | (c & d);
|
1152
|
+
}
|
1153
|
+
return b ^ c ^ d;
|
1154
|
+
},
|
1155
|
+
sha1_kt: function(t) {
|
1156
|
+
if (t < 20) {
|
1157
|
+
return 1518500249;
|
1158
|
+
} else {
|
1159
|
+
if (t < 40) {
|
1160
|
+
return 1859775393;
|
1161
|
+
} else {
|
1162
|
+
if (t < 60) {
|
1163
|
+
return -1894007588;
|
1164
|
+
} else {
|
1165
|
+
return -899497514;
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
}
|
1169
|
+
},
|
1170
|
+
safe_add: function(x, y) {
|
1171
|
+
var lsw, msw;
|
1172
|
+
lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
1173
|
+
msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
1174
|
+
return (msw << 16) | (lsw & 0xFFFF);
|
1175
|
+
},
|
1176
|
+
bit_rol: function(num, cnt) {
|
1177
|
+
return (num << cnt) | (num >>> (32 - cnt));
|
1178
|
+
},
|
1179
|
+
create_hash: function() {
|
1180
|
+
var hash;
|
1181
|
+
hash = this.b64_sha1((new Date()).getTime() + ":" + Math.floor(Math.random() * 9999999));
|
1182
|
+
return hash.replace(/\+/g, "-").replace(/\//g, "_").replace(/\=+$/, "");
|
1183
|
+
}
|
1184
|
+
};
|
1185
|
+
|
1186
|
+
},{}],8:[function(require,module,exports){
|
1187
|
+
module.exports = function(document) {
|
1188
|
+
return {
|
1189
|
+
getAbsUrl: function(url) {
|
1190
|
+
var base_url;
|
1191
|
+
if (url.match(/^.{2,5}:\/\//)) {
|
1192
|
+
return url;
|
1193
|
+
}
|
1194
|
+
if (url[0] === "/") {
|
1195
|
+
return document.location.protocol + "//" + document.location.host + url;
|
1196
|
+
}
|
1197
|
+
base_url = document.location.protocol + "//" + document.location.host + document.location.pathname;
|
1198
|
+
if (base_url[base_url.length - 1] !== "/" && url[0] !== "#") {
|
1199
|
+
return base_url + "/" + url;
|
1200
|
+
}
|
1201
|
+
return base_url + url;
|
1202
|
+
},
|
1203
|
+
replaceParam: function(param, rep, rep2) {
|
1204
|
+
param = param.replace(/\{\{(.*?)\}\}/g, function(m, v) {
|
1205
|
+
return rep[v] || "";
|
1206
|
+
});
|
1207
|
+
if (rep2) {
|
1208
|
+
param = param.replace(/\{(.*?)\}/g, function(m, v) {
|
1209
|
+
return rep2[v] || "";
|
1210
|
+
});
|
1211
|
+
}
|
1212
|
+
return param;
|
1213
|
+
}
|
1214
|
+
};
|
1215
|
+
};
|
1216
|
+
|
1217
|
+
},{}]},{},[4])
|