ember-auth-source 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/dist/ember-auth.js +419 -0
- data/lib/ember-auth/source.rb +7 -0
- metadata +67 -0
data/dist/ember-auth.js
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* jQuery Cookie Plugin v1.3.1
|
|
3
|
+
* https://github.com/carhartl/jquery-cookie
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2013 Klaus Hartl
|
|
6
|
+
* Released under the MIT license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
(function (factory) {
|
|
10
|
+
if (typeof define === 'function' && define.amd && define.amd.jQuery) {
|
|
11
|
+
// AMD. Register as anonymous module.
|
|
12
|
+
define(['jquery'], factory);
|
|
13
|
+
} else {
|
|
14
|
+
// Browser globals.
|
|
15
|
+
factory(jQuery);
|
|
16
|
+
}
|
|
17
|
+
}(function ($) {
|
|
18
|
+
|
|
19
|
+
var pluses = /\+/g;
|
|
20
|
+
|
|
21
|
+
function raw(s) {
|
|
22
|
+
return s;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function decoded(s) {
|
|
26
|
+
return decodeURIComponent(s.replace(pluses, ' '));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function converted(s) {
|
|
30
|
+
if (s.indexOf('"') === 0) {
|
|
31
|
+
// This is a quoted cookie as according to RFC2068, unescape
|
|
32
|
+
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return config.json ? JSON.parse(s) : s;
|
|
36
|
+
} catch(er) {}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var config = $.cookie = function (key, value, options) {
|
|
40
|
+
|
|
41
|
+
// write
|
|
42
|
+
if (value !== undefined) {
|
|
43
|
+
options = $.extend({}, config.defaults, options);
|
|
44
|
+
|
|
45
|
+
if (typeof options.expires === 'number') {
|
|
46
|
+
var days = options.expires, t = options.expires = new Date();
|
|
47
|
+
t.setDate(t.getDate() + days);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
value = config.json ? JSON.stringify(value) : String(value);
|
|
51
|
+
|
|
52
|
+
return (document.cookie = [
|
|
53
|
+
encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
|
|
54
|
+
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
|
55
|
+
options.path ? '; path=' + options.path : '',
|
|
56
|
+
options.domain ? '; domain=' + options.domain : '',
|
|
57
|
+
options.secure ? '; secure' : ''
|
|
58
|
+
].join(''));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// read
|
|
62
|
+
var decode = config.raw ? raw : decoded;
|
|
63
|
+
var cookies = document.cookie.split('; ');
|
|
64
|
+
var result = key ? undefined : {};
|
|
65
|
+
for (var i = 0, l = cookies.length; i < l; i++) {
|
|
66
|
+
var parts = cookies[i].split('=');
|
|
67
|
+
var name = decode(parts.shift());
|
|
68
|
+
var cookie = decode(parts.join('='));
|
|
69
|
+
|
|
70
|
+
if (key && key === name) {
|
|
71
|
+
result = converted(cookie);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!key) {
|
|
76
|
+
result[name] = converted(cookie);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
config.defaults = {};
|
|
84
|
+
|
|
85
|
+
$.removeCookie = function (key, options) {
|
|
86
|
+
if ($.cookie(key) !== undefined) {
|
|
87
|
+
$.cookie(key, '', $.extend(options, { expires: -1 }));
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
}));
|
|
94
|
+
(function() {
|
|
95
|
+
var evented;
|
|
96
|
+
|
|
97
|
+
evented = Em.Object.extend(Em.Evented);
|
|
98
|
+
|
|
99
|
+
window.Auth = evented.create({
|
|
100
|
+
authToken: null,
|
|
101
|
+
currentUserId: null,
|
|
102
|
+
currentUser: null,
|
|
103
|
+
jqxhr: null,
|
|
104
|
+
prevRoute: null,
|
|
105
|
+
json: null,
|
|
106
|
+
signIn: function(data) {
|
|
107
|
+
var async,
|
|
108
|
+
_this = this;
|
|
109
|
+
|
|
110
|
+
if (data == null) {
|
|
111
|
+
data = {};
|
|
112
|
+
}
|
|
113
|
+
async = data.async != null ? data.async : true;
|
|
114
|
+
if (data.async != null) {
|
|
115
|
+
delete data['async'];
|
|
116
|
+
}
|
|
117
|
+
return this.ajax({
|
|
118
|
+
url: this.resolveUrl(Auth.Config.get('tokenCreateUrl')),
|
|
119
|
+
type: 'POST',
|
|
120
|
+
data: data,
|
|
121
|
+
async: async
|
|
122
|
+
}).done(function(json, status, jqxhr) {
|
|
123
|
+
var model;
|
|
124
|
+
|
|
125
|
+
_this.set('authToken', json[Auth.Config.get('tokenKey')]);
|
|
126
|
+
_this.set('currentUserId', json[Auth.Config.get('idKey')]);
|
|
127
|
+
if (model = Auth.Config.get('userModel')) {
|
|
128
|
+
_this.set('currentUser', model.find(_this.get('currentUserId')));
|
|
129
|
+
}
|
|
130
|
+
_this.set('json', json);
|
|
131
|
+
_this.set('jqxhr', jqxhr);
|
|
132
|
+
return _this.trigger('signInSuccess');
|
|
133
|
+
}).fail(function(jqxhr) {
|
|
134
|
+
_this.set('jqxhr', jqxhr);
|
|
135
|
+
return _this.trigger('signInError');
|
|
136
|
+
}).always(function(jqxhr) {
|
|
137
|
+
_this.set('prevRoute', null);
|
|
138
|
+
_this.set('jqxhr', jqxhr);
|
|
139
|
+
return _this.trigger('signInComplete');
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
signOut: function(data) {
|
|
143
|
+
var async,
|
|
144
|
+
_this = this;
|
|
145
|
+
|
|
146
|
+
if (data == null) {
|
|
147
|
+
data = {};
|
|
148
|
+
}
|
|
149
|
+
data[Auth.Config.get('tokenKey')] = this.get('authToken');
|
|
150
|
+
async = data.async != null ? data.async : true;
|
|
151
|
+
if (data.async != null) {
|
|
152
|
+
delete data['async'];
|
|
153
|
+
}
|
|
154
|
+
return this.ajax({
|
|
155
|
+
url: this.resolveUrl(Auth.Config.get('tokenDestroyUrl')),
|
|
156
|
+
type: 'DELETE',
|
|
157
|
+
data: data,
|
|
158
|
+
async: async
|
|
159
|
+
}).done(function(json, status, jqxhr) {
|
|
160
|
+
_this.set('authToken', null);
|
|
161
|
+
_this.set('currentUserId', null);
|
|
162
|
+
_this.set('currentUser', null);
|
|
163
|
+
_this.set('jqxhr', jqxhr);
|
|
164
|
+
_this.set('json', json);
|
|
165
|
+
return _this.trigger('signOutSuccess');
|
|
166
|
+
}).fail(function(jqxhr) {
|
|
167
|
+
_this.set('jqxhr', jqxhr);
|
|
168
|
+
return _this.trigger('signOutError');
|
|
169
|
+
}).always(function(jqxhr) {
|
|
170
|
+
_this.set('prevRoute', null);
|
|
171
|
+
_this.set('jqxhr', jqxhr);
|
|
172
|
+
return _this.trigger('signOutComplete');
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
resolveUrl: function(path) {
|
|
176
|
+
var base;
|
|
177
|
+
|
|
178
|
+
base = Auth.Config.get('baseUrl');
|
|
179
|
+
if (base && base[base.length - 1] === '/') {
|
|
180
|
+
base = base.substr(0, base.length - 1);
|
|
181
|
+
}
|
|
182
|
+
if ((path != null ? path[0] : void 0) === '/') {
|
|
183
|
+
path = path.substr(1, path.length);
|
|
184
|
+
}
|
|
185
|
+
return [base, path].join('/');
|
|
186
|
+
},
|
|
187
|
+
resolveRedirectRoute: function(type) {
|
|
188
|
+
var fallback, isSmart, sameRoute, typeClassCase;
|
|
189
|
+
|
|
190
|
+
if (type !== 'signIn' && type !== 'signOut') {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
typeClassCase = "" + (type[0].toUpperCase()) + (type.slice(1));
|
|
194
|
+
isSmart = Auth.Config.get("smart" + typeClassCase + "Redirect");
|
|
195
|
+
fallback = Auth.Config.get("" + type + "RedirectFallbackRoute");
|
|
196
|
+
sameRoute = Auth.Config.get("" + type + "Route");
|
|
197
|
+
if (!isSmart) {
|
|
198
|
+
return fallback;
|
|
199
|
+
}
|
|
200
|
+
if ((this.prevRoute == null) || this.prevRoute === sameRoute) {
|
|
201
|
+
return fallback;
|
|
202
|
+
} else {
|
|
203
|
+
return this.prevRoute;
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
ajax: function(settings) {
|
|
207
|
+
var def, token;
|
|
208
|
+
|
|
209
|
+
def = {};
|
|
210
|
+
if (token = this.get('authToken')) {
|
|
211
|
+
switch (Auth.Config.get('requestTokenLocation')) {
|
|
212
|
+
case 'param':
|
|
213
|
+
def.data || (def.data = {});
|
|
214
|
+
def.data[Auth.Config.get('tokenKey')] = this.get('authToken');
|
|
215
|
+
break;
|
|
216
|
+
case 'authHeader':
|
|
217
|
+
def.headers || (def.headers = {});
|
|
218
|
+
def.headers['Authorization'] = "" + (Auth.Config.get('requestHeaderKey')) + " " + (this.get('authToken'));
|
|
219
|
+
break;
|
|
220
|
+
case 'customHeader':
|
|
221
|
+
def.headers || (def.headers = {});
|
|
222
|
+
def.headers[Auth.Config.get('requestHeaderKey')] = this.get('authToken');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
def.dataType = 'json';
|
|
226
|
+
def.contentType = 'application/json; charset=utf-8';
|
|
227
|
+
if (def.data && settings.type !== 'GET') {
|
|
228
|
+
def.data = JSON.stringify(settings.data);
|
|
229
|
+
}
|
|
230
|
+
settings = jQuery.extend(def, settings);
|
|
231
|
+
return jQuery.ajax(settings);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
}).call(this);
|
|
236
|
+
(function() {
|
|
237
|
+
Auth.Config = Em.Object.create({
|
|
238
|
+
tokenCreateUrl: null,
|
|
239
|
+
tokenDestroyUrl: null,
|
|
240
|
+
tokenKey: null,
|
|
241
|
+
idKey: null,
|
|
242
|
+
userModel: null,
|
|
243
|
+
baseUrl: null,
|
|
244
|
+
requestTokenLocation: 'param',
|
|
245
|
+
requestHeaderKey: null,
|
|
246
|
+
signInRoute: null,
|
|
247
|
+
signOutRoute: null,
|
|
248
|
+
authRedirect: false,
|
|
249
|
+
smartSignInRedirect: false,
|
|
250
|
+
smartSignOutRedirect: false,
|
|
251
|
+
signInRedirectFallbackRoute: 'index',
|
|
252
|
+
signOutRedirectFallbackRoute: 'index',
|
|
253
|
+
rememberMe: false,
|
|
254
|
+
rememberTokenKey: null,
|
|
255
|
+
rememberPeriod: 14,
|
|
256
|
+
rememberAutoRecall: true,
|
|
257
|
+
rememberStorage: 'cookie'
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
}).call(this);
|
|
261
|
+
(function() {
|
|
262
|
+
Auth.Route = Em.Route.extend(Em.Evented, {
|
|
263
|
+
redirect: function() {
|
|
264
|
+
if (!Auth.get('authToken')) {
|
|
265
|
+
this.trigger('authAccess');
|
|
266
|
+
if (Auth.Config.get('authRedirect')) {
|
|
267
|
+
Auth.set('prevRoute', this.routeName);
|
|
268
|
+
return this.transitionTo(Auth.Config.get('signInRoute'));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
}).call(this);
|
|
275
|
+
(function() {
|
|
276
|
+
Auth.SignInController = Em.Mixin.create({
|
|
277
|
+
registerRedirect: function() {
|
|
278
|
+
return Auth.addObserver('authToken', this, 'smartSignInRedirect');
|
|
279
|
+
},
|
|
280
|
+
smartSignInRedirect: function() {
|
|
281
|
+
if (Auth.get('authToken')) {
|
|
282
|
+
this.transitionToRoute(Auth.resolveRedirectRoute('signIn'));
|
|
283
|
+
return Auth.removeObserver('authToken', this, 'smartSignInRedirect');
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
}).call(this);
|
|
289
|
+
(function() {
|
|
290
|
+
Auth.SignOutController = Em.Mixin.create({
|
|
291
|
+
registerRedirect: function() {
|
|
292
|
+
return Auth.addObserver('authToken', this, 'smartSignOutRedirect');
|
|
293
|
+
},
|
|
294
|
+
smartSignOutRedirect: function() {
|
|
295
|
+
if (!Auth.get('authToken')) {
|
|
296
|
+
this.transitionToRoute(Auth.resolveRedirectRoute('signOut'));
|
|
297
|
+
return Auth.removeObserver('authToken', this, 'smartSignOutRedirect');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
}).call(this);
|
|
303
|
+
(function() {
|
|
304
|
+
Auth.RESTAdapter = DS.RESTAdapter.extend({
|
|
305
|
+
ajax: function(url, type, settings) {
|
|
306
|
+
settings.url = url;
|
|
307
|
+
settings.type = type;
|
|
308
|
+
settings.context = this;
|
|
309
|
+
return Auth.ajax(settings);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
}).call(this);
|
|
314
|
+
(function() {
|
|
315
|
+
Auth.Module = Em.Object.create();
|
|
316
|
+
|
|
317
|
+
}).call(this);
|
|
318
|
+
(function() {
|
|
319
|
+
Auth.Module.RememberMe = Em.Object.create({
|
|
320
|
+
init: function() {
|
|
321
|
+
var _this = this;
|
|
322
|
+
|
|
323
|
+
Auth.on('signInSuccess', function() {
|
|
324
|
+
return _this.remember();
|
|
325
|
+
});
|
|
326
|
+
Auth.on('signInError', function() {
|
|
327
|
+
return _this.forget();
|
|
328
|
+
});
|
|
329
|
+
return Auth.on('signOutSuccess', function() {
|
|
330
|
+
return _this.forget();
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
recall: function(opts) {
|
|
334
|
+
var data, token;
|
|
335
|
+
|
|
336
|
+
if (opts == null) {
|
|
337
|
+
opts = {};
|
|
338
|
+
}
|
|
339
|
+
if (!Auth.Config.get('rememberMe')) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (!Auth.get('authToken') && (token = this.retrieveToken())) {
|
|
343
|
+
data = {};
|
|
344
|
+
if (opts.async != null) {
|
|
345
|
+
data['async'] = opts.async;
|
|
346
|
+
}
|
|
347
|
+
data[Auth.Config.get('rememberTokenKey')] = token;
|
|
348
|
+
return Auth.signIn(data);
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
remember: function() {
|
|
352
|
+
var token;
|
|
353
|
+
|
|
354
|
+
if (!Auth.Config.get('rememberMe')) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
token = Auth.get('json')[Auth.Config.get('rememberTokenKey')];
|
|
358
|
+
if (token && token !== this.retrieveToken()) {
|
|
359
|
+
return this.storeToken(token);
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
forget: function() {
|
|
363
|
+
if (!Auth.Config.get('rememberMe')) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
return this.removeToken();
|
|
367
|
+
},
|
|
368
|
+
retrieveToken: function() {
|
|
369
|
+
switch (Auth.Config.get('rememberStorage')) {
|
|
370
|
+
case 'localStorage':
|
|
371
|
+
return localStorage.getItem('ember-auth-remember-me');
|
|
372
|
+
case 'cookie':
|
|
373
|
+
return jQuery.cookie('ember-auth-remember-me');
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
storeToken: function(token) {
|
|
377
|
+
switch (Auth.Config.get('rememberStorage')) {
|
|
378
|
+
case 'localStorage':
|
|
379
|
+
return localStorage.setItem('ember-auth-remember-me', token);
|
|
380
|
+
case 'cookie':
|
|
381
|
+
return jQuery.cookie('ember-auth-remember-me', token, {
|
|
382
|
+
expires: Auth.Config.get('rememberPeriod')
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
removeToken: function() {
|
|
387
|
+
switch (Auth.Config.get('rememberStorage')) {
|
|
388
|
+
case 'localStorage':
|
|
389
|
+
return localStorage.removeItem('ember-auth-remember-me');
|
|
390
|
+
case 'cookie':
|
|
391
|
+
return jQuery.removeCookie('ember-auth-remember-me');
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
Auth.Route.reopen({
|
|
397
|
+
redirect: function() {
|
|
398
|
+
var callback, request, self;
|
|
399
|
+
|
|
400
|
+
if (Auth.Config.get('rememberMe') && Auth.Config.get('rememberAutoRecall')) {
|
|
401
|
+
if (request = Auth.Module.RememberMe.recall({
|
|
402
|
+
async: false
|
|
403
|
+
})) {
|
|
404
|
+
self = this;
|
|
405
|
+
callback = this._super;
|
|
406
|
+
return request.always(function() {
|
|
407
|
+
return callback.call(self);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return this._super();
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
}).call(this);
|
|
416
|
+
(function() {
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
}).call(this);
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ember-auth-source
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 3.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- heartsentwined
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-04-06 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: ember-rails
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0.10'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0.10'
|
|
30
|
+
description: Ember-auth source code wrapper for ruby libs.
|
|
31
|
+
email:
|
|
32
|
+
- heartsentwined@cogito-lab.com
|
|
33
|
+
executables: []
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- dist/ember-auth.js
|
|
38
|
+
- lib/ember-auth/source.rb
|
|
39
|
+
homepage: https://github.com/heartsentwined/ember-auth
|
|
40
|
+
licenses:
|
|
41
|
+
- GPL-3
|
|
42
|
+
post_install_message:
|
|
43
|
+
rdoc_options: []
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
none: false
|
|
48
|
+
requirements:
|
|
49
|
+
- - ! '>='
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0'
|
|
52
|
+
segments:
|
|
53
|
+
- 0
|
|
54
|
+
hash: 332335407
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
none: false
|
|
57
|
+
requirements:
|
|
58
|
+
- - ! '>='
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
requirements: []
|
|
62
|
+
rubyforge_project:
|
|
63
|
+
rubygems_version: 1.8.25
|
|
64
|
+
signing_key:
|
|
65
|
+
specification_version: 3
|
|
66
|
+
summary: Ember-auth source code wrapper
|
|
67
|
+
test_files: []
|