ember_simple_auth-rails 0.6.3 → 0.6.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6114507e7e5eeef52db1098b98f10d9dc483d29
4
- data.tar.gz: 97a46d0071cce71416c5c290d7b45ba939f0b294
3
+ metadata.gz: 719d3390d677fc68f07d4c9b56d6997a22af2730
4
+ data.tar.gz: a414a5634f5252c0dd3d33ced15a4d4c140db9d4
5
5
  SHA512:
6
- metadata.gz: e721d44e48b6e4155d5f23afeb7cd7d3e3b51bcbb98fd88c25b62886230763af840d320ece40eb49555cd2a0a31158fe7f6b27e1e2cea9de6bb15873de99c666
7
- data.tar.gz: 91e92b317511b1a7eaefabc052cbb347b1ed52e7607e2122520e48a623bdb7459d2f3f87c45b9d3cdb81bfe20d2ffb8f4e54c5d6b3a95c51945e2c013d8e9f64
6
+ metadata.gz: e06686f14ed887bbcd5b028d9a6c6ca74436cac09f04feda5316bf597939b779fc5f6c6a270a6c81d2521490c93af8fc267d647962b9901ce5025828f202f9a3
7
+ data.tar.gz: b372da27a81fbb7bf92ccacd3733cbe538a111de9e57dfa5e20b0df3a2b5e048367718a3291203fdb3f566b335096c913af955545da030de9fde8b2e838edc5a
@@ -1,5 +1,5 @@
1
1
  module EmberSimpleAuth
2
2
  module Rails
3
- VERSION = "0.6.3"
3
+ VERSION = "0.6.4"
4
4
  end
5
5
  end
@@ -1,5 +1,7 @@
1
1
  (function(global) {
2
2
 
3
+ Ember.libraries.register('Ember Simple Auth Cookie Store', '0.6.4');
4
+
3
5
  var define, requireModule;
4
6
 
5
7
  (function() {
@@ -58,9 +60,6 @@ define("simple-auth-cookie-store/ember",
58
60
  ["./initializer"],
59
61
  function(__dependency1__) {
60
62
  "use strict";
61
- var global = (typeof window !== 'undefined') ? window : {},
62
- Ember = global.Ember;
63
-
64
63
  var initializer = __dependency1__["default"];
65
64
 
66
65
  Ember.onLoad('Ember.Application', function(Application) {
@@ -71,9 +70,6 @@ define("simple-auth-cookie-store/initializer",
71
70
  ["simple-auth-cookie-store/stores/cookie","exports"],
72
71
  function(__dependency1__, __exports__) {
73
72
  "use strict";
74
- var global = (typeof window !== 'undefined') ? window : {},
75
- Ember = global.Ember;
76
-
77
73
  var Store = __dependency1__["default"];
78
74
 
79
75
  __exports__["default"] = {
@@ -92,20 +88,17 @@ define("simple-auth-cookie-store/stores/cookie",
92
88
  var flatObjectsAreEqual = __dependency2__["default"];
93
89
  var getGlobalConfig = __dependency3__["default"];
94
90
 
95
- var global = (typeof window !== 'undefined') ? window : {},
96
- Ember = global.Ember;
97
-
98
91
  /**
99
- Store that saves its data in cookies.
92
+ Store that saves its data in a cookie.
100
93
 
101
94
  __In order to keep multiple tabs/windows of an application in sync, this
102
- store has to periodically (every 500ms) check the cookies__ for changes as
95
+ store has to periodically (every 500ms) check the cookie__ for changes as
103
96
  there are no events that notify of changes in cookies. The recommended
104
97
  alternative is `Stores.LocalStorage` that also persistently stores data but
105
98
  instead of cookies relies on the `localStorage` API and does not need to poll
106
99
  for external changes.
107
100
 
108
- By default the cookie store will use session cookies that expire and are
101
+ By default the cookie store will use a session cookie that expires and is
109
102
  deleted when the browser is closed. The cookie expiration period can be
110
103
  configured via setting
111
104
  [`Stores.Cooke#cookieExpirationTime`](#SimpleAuth-Stores-Cookie-cookieExpirationTime)
@@ -136,27 +129,26 @@ define("simple-auth-cookie-store/stores/cookie",
136
129
  */
137
130
  __exports__["default"] = Base.extend({
138
131
  /**
139
- The prefix to use for the store's cookie names so they can be distinguished
140
- from other cookies.
132
+ The name of the cookie the store stores its data in.
141
133
 
142
134
  This value can be configured via the global environment object:
143
135
 
144
136
  ```js
145
137
  window.ENV = window.ENV || {};
146
138
  window.ENV['simple-auth-cookie-store'] = {
147
- cookieNamePrefix: 'my_app_auth_'
139
+ cookieName: 'my_app_auth_session'
148
140
  }
149
141
  ```
150
142
 
151
- @property cookieNamePrefix
143
+ @property cookieName
152
144
  @type String
153
145
  @default 'ember_simple_auth:'
154
146
  */
155
- cookieNamePrefix: 'ember_simple_auth:',
147
+ cookieName: 'ember_simple_auth:session',
156
148
 
157
149
  /**
158
- The expiration time in seconds to use for the cookies. A value of `null`
159
- will make the cookies session cookies that expire when the browser is
150
+ The expiration time in seconds to use for the cookie. A value of `null`
151
+ will make the cookie a session cookie that expires when the browser is
160
152
  closed.
161
153
 
162
154
  This value can be configured via the global environment object:
@@ -192,7 +184,7 @@ define("simple-auth-cookie-store/stores/cookie",
192
184
  */
193
185
  init: function() {
194
186
  var globalConfig = getGlobalConfig('simple-auth-cookie-store');
195
- this.cookieNamePrefix = globalConfig.cookieNamePrefix || this.cookieNamePrefix;
187
+ this.cookieName = globalConfig.cookieName || this.cookieName;
196
188
  this.cookieExpirationTime = globalConfig.cookieExpirationTime || this.cookieExpirationTime;
197
189
  this.syncData();
198
190
  },
@@ -204,42 +196,36 @@ define("simple-auth-cookie-store/stores/cookie",
204
196
  @param {Object} data The data to persist
205
197
  */
206
198
  persist: function(data) {
207
- for (var property in data) {
208
- this.write(property, data[property], !!this.cookieExpirationTime ? new Date().getTime() + this.cookieExpirationTime * 1000 : null);
209
- }
199
+ data = JSON.stringify(data || {});
200
+ var expiration = !!this.cookieExpirationTime ? new Date().getTime() + this.cookieExpirationTime * 1000 : null;
201
+ this.write(data, expiration);
210
202
  this._lastData = this.restore();
211
203
  },
212
204
 
213
205
  /**
214
- Restores all data currently saved in the session cookies identified by the
215
- `cookieNamePrefix` (see
216
- [`Stores.Cookie#cookieNamePrefix`](#SimpleAuth-Stores-Cookie-cookieNamePrefix))
217
- as a plain object.
206
+ Restores all data currently saved in the cookie as a plain object.
218
207
 
219
208
  @method restore
220
- @return {Object} All data currently persisted in the session cookies
209
+ @return {Object} All data currently persisted in the cookie
221
210
  */
222
211
  restore: function() {
223
- var _this = this;
224
- var data = {};
225
- this.knownCookies().forEach(function(cookie) {
226
- data[cookie] = _this.read(cookie);
227
- });
228
- return data;
212
+ var data = this.read();
213
+ if (Ember.isEmpty(data)) {
214
+ return {};
215
+ } else {
216
+ return JSON.parse(data);
217
+ }
229
218
  },
230
219
 
231
220
  /**
232
221
  Clears the store by deleting all session cookies prefixed with the
233
- `cookieNamePrefix` (see
234
- [`SimpleAuth.Stores.Cookie#cookieNamePrefix`](#SimpleAuth-Stores-Cookie-cookieNamePrefix)).
222
+ `cookieName` (see
223
+ [`SimpleAuth.Stores.Cookie#cookieName`](#SimpleAuth-Stores-Cookie-cookieName)).
235
224
 
236
225
  @method clear
237
226
  */
238
227
  clear: function() {
239
- var _this = this;
240
- this.knownCookies().forEach(function(cookie) {
241
- _this.write(cookie, null, 0);
242
- });
228
+ this.write(null, 0);
243
229
  this._lastData = null;
244
230
  },
245
231
 
@@ -247,8 +233,8 @@ define("simple-auth-cookie-store/stores/cookie",
247
233
  @method read
248
234
  @private
249
235
  */
250
- read: function(name) {
251
- var value = document.cookie.match(new RegExp(this.cookieNamePrefix + name + '=([^;]+)')) || [];
236
+ read: function() {
237
+ var value = document.cookie.match(new RegExp(this.cookieName + name + '=([^;]+)')) || [];
252
238
  return decodeURIComponent(value[1] || '');
253
239
  },
254
240
 
@@ -256,23 +242,10 @@ define("simple-auth-cookie-store/stores/cookie",
256
242
  @method write
257
243
  @private
258
244
  */
259
- write: function(name, value, expiration) {
245
+ write: function(value, expiration) {
260
246
  var expires = Ember.isEmpty(expiration) ? '' : '; expires=' + new Date(expiration).toUTCString();
261
247
  var secure = !!this._secureCookies ? ';secure' : '';
262
- document.cookie = this.cookieNamePrefix + name + '=' + encodeURIComponent(value) + expires + secure;
263
- },
264
-
265
- /**
266
- @method knownCookies
267
- @private
268
- */
269
- knownCookies: function() {
270
- var _this = this;
271
- return Ember.A(document.cookie.split(/[=;\s]+/)).filter(function(element) {
272
- return new RegExp('^' + _this.cookieNamePrefix).test(element);
273
- }).map(function(cookie) {
274
- return cookie.replace(_this.cookieNamePrefix, '');
275
- });
248
+ document.cookie = this.cookieName + '=' + encodeURIComponent(value) + expires + secure;
276
249
  },
277
250
 
278
251
  /**
@@ -1,5 +1,7 @@
1
1
  (function(global) {
2
2
 
3
+ Ember.libraries.register('Ember Simple Auth Devise', '0.6.4');
4
+
3
5
  var define, requireModule;
4
6
 
5
7
  (function() {
@@ -62,9 +64,6 @@ define("simple-auth-devise/authenticators/devise",
62
64
  var isSecureUrl = __dependency2__["default"];
63
65
  var getGlobalConfig = __dependency3__["default"];
64
66
 
65
- var global = (typeof window !== 'undefined') ? window : {},
66
- Ember = global.Ember;
67
-
68
67
  /**
69
68
  Authenticator that works with the Ruby gem
70
69
  [Devise](https://github.com/plataformatec/devise).
@@ -219,9 +218,6 @@ define("simple-auth-devise/authorizers/devise",
219
218
  var Base = __dependency1__["default"];
220
219
  var isSecureUrl = __dependency2__["default"];
221
220
 
222
- var global = (typeof window !== 'undefined') ? window : {},
223
- Ember = global.Ember;
224
-
225
221
  /**
226
222
  Authenticator that works with the Ruby gem
227
223
  [Devise](https://github.com/plataformatec/devise) by sending the `user_token`
@@ -270,9 +266,6 @@ define("simple-auth-devise/ember",
270
266
  ["./initializer"],
271
267
  function(__dependency1__) {
272
268
  "use strict";
273
- var global = (typeof window !== 'undefined') ? window : {},
274
- Ember = global.Ember;
275
-
276
269
  var initializer = __dependency1__["default"];
277
270
 
278
271
  Ember.onLoad('Ember.Application', function(Application) {
@@ -283,9 +276,6 @@ define("simple-auth-devise/initializer",
283
276
  ["simple-auth-devise/authenticators/devise","simple-auth-devise/authorizers/devise","exports"],
284
277
  function(__dependency1__, __dependency2__, __exports__) {
285
278
  "use strict";
286
- var global = (typeof window !== 'undefined') ? window : {},
287
- Ember = global.Ember;
288
-
289
279
  var Authenticator = __dependency1__["default"];
290
280
  var Authorizer = __dependency2__["default"];
291
281
 
@@ -1,5 +1,7 @@
1
1
  (function(global) {
2
2
 
3
+ Ember.libraries.register('Ember Simple Auth OAuth 2.0', '0.6.4');
4
+
3
5
  var define, requireModule;
4
6
 
5
7
  (function() {
@@ -62,9 +64,6 @@ define("simple-auth-oauth2/authenticators/oauth2",
62
64
  var isSecureUrl = __dependency2__["default"];
63
65
  var getGlobalConfig = __dependency3__["default"];
64
66
 
65
- var global = (typeof window !== 'undefined') ? window : {},
66
- Ember = global.Ember;
67
-
68
67
  /**
69
68
  Authenticator that conforms to OAuth 2
70
69
  ([RFC 6749](http://tools.ietf.org/html/rfc6749)), specifically the _"Resource
@@ -181,22 +180,22 @@ define("simple-auth-oauth2/authenticators/oauth2",
181
180
  restore: function(data) {
182
181
  var _this = this;
183
182
  return new Ember.RSVP.Promise(function(resolve, reject) {
184
- if (!Ember.isEmpty(data.access_token)) {
185
- var now = (new Date()).getTime();
186
- if (!Ember.isEmpty(data.expires_at) && data.expires_at < now) {
187
- if (_this.refreshAccessTokens) {
188
- _this.refreshAccessToken(data.expires_in, data.refresh_token).then(function(data) {
189
- resolve(data);
190
- }, reject);
191
- } else {
192
- reject();
193
- }
183
+ var now = (new Date()).getTime();
184
+ if (!Ember.isEmpty(data.expires_at) && data.expires_at < now) {
185
+ if (_this.refreshAccessTokens) {
186
+ _this.refreshAccessToken(data.expires_in, data.refresh_token).then(function(data) {
187
+ resolve(data);
188
+ }, reject);
189
+ } else {
190
+ reject();
191
+ }
192
+ } else {
193
+ if (Ember.isEmpty(data.access_token)) {
194
+ reject();
194
195
  } else {
195
196
  _this.scheduleAccessTokenRefresh(data.expires_in, data.expires_at, data.refresh_token);
196
197
  resolve(data);
197
198
  }
198
- } else {
199
- reject();
200
199
  }
201
200
  });
202
201
  },
@@ -228,7 +227,10 @@ define("simple-auth-oauth2/authenticators/oauth2",
228
227
  Ember.run(function() {
229
228
  var expiresAt = _this.absolutizeExpirationTime(response.expires_in);
230
229
  _this.scheduleAccessTokenRefresh(response.expires_in, expiresAt, response.refresh_token);
231
- resolve(Ember.$.extend(response, { expires_at: expiresAt }));
230
+ if (!Ember.isEmpty(expiresAt)) {
231
+ response = Ember.merge(response, { expires_at: expiresAt });
232
+ }
233
+ resolve(response);
232
234
  });
233
235
  }, function(xhr, status, error) {
234
236
  Ember.run(function() {
@@ -311,7 +313,7 @@ define("simple-auth-oauth2/authenticators/oauth2",
311
313
  if (Ember.isEmpty(expiresAt) && !Ember.isEmpty(expiresIn)) {
312
314
  expiresAt = new Date(now + expiresIn * 1000).getTime();
313
315
  }
314
- var offset = (Math.floor(Math.random() * 15) + 5) * 1000;
316
+ var offset = (Math.floor(Math.random() * 5) + 5) * 1000;
315
317
  if (!Ember.isEmpty(refreshToken) && !Ember.isEmpty(expiresAt) && expiresAt > now - offset) {
316
318
  Ember.run.cancel(this._refreshTokenTimeout);
317
319
  delete this._refreshTokenTimeout;
@@ -335,7 +337,7 @@ define("simple-auth-oauth2/authenticators/oauth2",
335
337
  expiresIn = response.expires_in || expiresIn;
336
338
  refreshToken = response.refresh_token || refreshToken;
337
339
  var expiresAt = _this.absolutizeExpirationTime(expiresIn);
338
- var data = Ember.$.extend(response, { expires_in: expiresIn, expires_at: expiresAt, refresh_token: refreshToken });
340
+ var data = Ember.merge(response, { expires_in: expiresIn, expires_at: expiresAt, refresh_token: refreshToken });
339
341
  _this.scheduleAccessTokenRefresh(expiresIn, null, refreshToken);
340
342
  _this.trigger('sessionDataUpdated', data);
341
343
  resolve(data);
@@ -353,7 +355,7 @@ define("simple-auth-oauth2/authenticators/oauth2",
353
355
  */
354
356
  absolutizeExpirationTime: function(expiresIn) {
355
357
  if (!Ember.isEmpty(expiresIn)) {
356
- return new Date((new Date().getTime()) + (expiresIn - 5) * 1000).getTime();
358
+ return new Date((new Date().getTime()) + expiresIn * 1000).getTime();
357
359
  }
358
360
  }
359
361
  });
@@ -365,9 +367,6 @@ define("simple-auth-oauth2/authorizers/oauth2",
365
367
  var Base = __dependency1__["default"];
366
368
  var isSecureUrl = __dependency2__["default"];
367
369
 
368
- var global = (typeof window !== 'undefined') ? window : {},
369
- Ember = global.Ember;
370
-
371
370
  /**
372
371
  Authorizer that conforms to OAuth 2
373
372
  ([RFC 6749](http://tools.ietf.org/html/rfc6749)) by sending a bearer token
@@ -410,9 +409,6 @@ define("simple-auth-oauth2/ember",
410
409
  ["./initializer"],
411
410
  function(__dependency1__) {
412
411
  "use strict";
413
- var global = (typeof window !== 'undefined') ? window : {},
414
- Ember = global.Ember;
415
-
416
412
  var initializer = __dependency1__["default"];
417
413
 
418
414
  Ember.onLoad('Ember.Application', function(Application) {
@@ -423,9 +419,6 @@ define("simple-auth-oauth2/initializer",
423
419
  ["simple-auth-oauth2/authenticators/oauth2","simple-auth-oauth2/authorizers/oauth2","exports"],
424
420
  function(__dependency1__, __dependency2__, __exports__) {
425
421
  "use strict";
426
- var global = (typeof window !== 'undefined') ? window : {},
427
- Ember = global.Ember;
428
-
429
422
  var Authenticator = __dependency1__["default"];
430
423
  var Authorizer = __dependency2__["default"];
431
424
 
@@ -0,0 +1,137 @@
1
+ (function(global) {
2
+
3
+ Ember.libraries.register('Ember Simple Auth Testing', '0.6.4');
4
+
5
+ var define, requireModule;
6
+
7
+ (function() {
8
+ var registry = {}, seen = {};
9
+
10
+ define = function(name, deps, callback) {
11
+ registry[name] = { deps: deps, callback: callback };
12
+ };
13
+
14
+ requireModule = function(name) {
15
+ if (seen.hasOwnProperty(name)) { return seen[name]; }
16
+ seen[name] = {};
17
+
18
+ if (!registry[name]) {
19
+ throw new Error("Could not find module " + name);
20
+ }
21
+
22
+ var mod = registry[name],
23
+ deps = mod.deps,
24
+ callback = mod.callback,
25
+ reified = [],
26
+ exports;
27
+
28
+ for (var i=0, l=deps.length; i<l; i++) {
29
+ if (deps[i] === 'exports') {
30
+ reified.push(exports = {});
31
+ } else {
32
+ reified.push(requireModule(resolve(deps[i])));
33
+ }
34
+ }
35
+
36
+ var value = callback.apply(this, reified);
37
+ return seen[name] = exports || value;
38
+
39
+ function resolve(child) {
40
+ if (child.charAt(0) !== '.') { return child; }
41
+ var parts = child.split("/");
42
+ var parentBase = name.split("/").slice(0, -1);
43
+
44
+ for (var i=0, l=parts.length; i<l; i++) {
45
+ var part = parts[i];
46
+
47
+ if (part === '..') { parentBase.pop(); }
48
+ else if (part === '.') { continue; }
49
+ else { parentBase.push(part); }
50
+ }
51
+
52
+ return parentBase.join("/");
53
+ }
54
+ };
55
+
56
+ requireModule.registry = registry;
57
+ })();
58
+
59
+ define("simple-auth-testing/authenticators/test",
60
+ ["simple-auth/authenticators/base","exports"],
61
+ function(__dependency1__, __exports__) {
62
+ "use strict";
63
+ var Base = __dependency1__["default"];
64
+
65
+ __exports__["default"] = Base.extend({
66
+ restore: function(data) {
67
+ return new Ember.RSVP.resolve();
68
+ },
69
+
70
+ authenticate: function(options) {
71
+ return new Ember.RSVP.resolve();
72
+ },
73
+
74
+ invalidate: function(data) {
75
+ return new Ember.RSVP.resolve();
76
+ }
77
+ });
78
+ });
79
+ define("simple-auth-testing/ember",
80
+ ["./initializer"],
81
+ function(__dependency1__) {
82
+ "use strict";
83
+ var initializer = __dependency1__["default"];
84
+
85
+ Ember.onLoad('Ember.Application', function(Application) {
86
+ Application.initializer(initializer);
87
+ });
88
+ });
89
+ define("simple-auth-testing/initializer",
90
+ ["simple-auth-testing/authenticators/test","exports"],
91
+ function(__dependency1__, __exports__) {
92
+ "use strict";
93
+ var TestAuthenticator = __dependency1__["default"];
94
+
95
+ __exports__["default"] = {
96
+ name: 'simple-auth-testing',
97
+ before: 'simple-auth',
98
+ initialize: function(container, application) {
99
+ container.register('simple-auth-authenticator:test', TestAuthenticator);
100
+ }
101
+ };
102
+ });
103
+ define("simple-auth-testing/test-helpers",
104
+ ["simple-auth/configuration","exports"],
105
+ function(__dependency1__, __exports__) {
106
+ "use strict";
107
+ var Configuration = __dependency1__["default"];
108
+
109
+ var testHelpers = function() {
110
+ Ember.Test.registerAsyncHelper('authenticateSession', function(app) {
111
+ var session = app.__container__.lookup(Configuration.session);
112
+ session.authenticate('simple-auth-authenticator:test');
113
+ return wait();
114
+ });
115
+
116
+ Ember.Test.registerAsyncHelper('invalidateSession', function(app) {
117
+ var session = app.__container__.lookup(Configuration.session);
118
+ if (session.get('isAuthenticated')) {
119
+ session.invalidate();
120
+ }
121
+ return wait();
122
+ });
123
+ }();
124
+
125
+ __exports__["default"] = testHelpers;
126
+ });
127
+ define('simple-auth/authenticators/base', ['exports'], function(__exports__) {
128
+ __exports__['default'] = global.SimpleAuth.Authenticators.Base;
129
+ });
130
+
131
+ requireModule('simple-auth-testing/ember');
132
+
133
+ if (global.Ember.testing) {
134
+ requireModule('simple-auth/test-helpers/authenticate-session');
135
+ requireModule('simple-auth/test-helpers/invalidate-session');
136
+ }
137
+ })((typeof global !== 'undefined') ? global : window);
@@ -1,5 +1,7 @@
1
1
  (function(global) {
2
2
 
3
+ Ember.libraries.register('Ember Simple Auth Torii', '0.6.4');
4
+
3
5
  var define, requireModule;
4
6
 
5
7
  (function() {
@@ -60,9 +62,6 @@ define("simple-auth-torii/authenticators/torii",
60
62
  "use strict";
61
63
  var Base = __dependency1__["default"];
62
64
 
63
- var global = (typeof window !== 'undefined') ? window : {},
64
- Ember = global.Ember;
65
-
66
65
  /**
67
66
  Authenticator that wraps the
68
67
  [Torii library](https://github.com/Vestorly/torii).
@@ -165,9 +164,6 @@ define("simple-auth-torii/ember",
165
164
  ["./initializer"],
166
165
  function(__dependency1__) {
167
166
  "use strict";
168
- var global = (typeof window !== 'undefined') ? window : {},
169
- Ember = global.Ember;
170
-
171
167
  var initializer = __dependency1__["default"];
172
168
 
173
169
  Ember.onLoad('Ember.Application', function(Application) {
@@ -1,5 +1,7 @@
1
1
  (function(global) {
2
2
 
3
+ Ember.libraries.register('Ember Simple Auth', '0.6.4');
4
+
3
5
  var define, requireModule;
4
6
 
5
7
  (function() {
@@ -58,9 +60,6 @@ define("simple-auth/authenticators/base",
58
60
  ["exports"],
59
61
  function(__exports__) {
60
62
  "use strict";
61
- var global = (typeof window !== 'undefined') ? window : {},
62
- Ember = global.Ember;
63
-
64
63
  /**
65
64
  The base for all authenticators. __This serves as a starting point for
66
65
  implementing custom authenticators and must not be used directly.__
@@ -200,9 +199,10 @@ define("simple-auth/authenticators/base",
200
199
  resolving promise and thus never intercepts session invalidation.
201
200
 
202
201
  @method invalidate
202
+ @param {Object} data The data that the session currently holds
203
203
  @return {Ember.RSVP.Promise} A promise that when it resolves results in the session being invalidated
204
204
  */
205
- invalidate: function() {
205
+ invalidate: function(data) {
206
206
  return new Ember.RSVP.resolve();
207
207
  }
208
208
  });
@@ -211,9 +211,6 @@ define("simple-auth/authorizers/base",
211
211
  ["exports"],
212
212
  function(__exports__) {
213
213
  "use strict";
214
- var global = (typeof window !== 'undefined') ? window : {},
215
- Ember = global.Ember;
216
-
217
214
  /**
218
215
  The base for all authorizers. __This serves as a starting point for
219
216
  implementing custom authorizers and must not be used directly.__
@@ -333,6 +330,19 @@ define("simple-auth/configuration",
333
330
  */
334
331
  authorizer: null,
335
332
 
333
+ /**
334
+ The session factory to use as it is registered with Ember's container,
335
+ see
336
+ [Ember's API docs](http://emberjs.com/api/classes/Ember.Application.html#method_register).
337
+
338
+ @property session
339
+ @readOnly
340
+ @static
341
+ @type String
342
+ @default 'simple-auth-session:main'
343
+ */
344
+ session: 'simple-auth-session:main',
345
+
336
346
  /**
337
347
  The store factory to use as it is registered with Ember's container, see
338
348
  [Ember's API docs](http://emberjs.com/api/classes/Ember.Application.html#method_register).
@@ -376,6 +386,7 @@ define("simple-auth/configuration",
376
386
  this.routeAfterAuthentication = globalConfig.routeAfterAuthentication || this.routeAfterAuthentication;
377
387
  this.sessionPropertyName = globalConfig.sessionPropertyName || this.sessionPropertyName;
378
388
  this.authorizer = globalConfig.authorizer || this.authorizer;
389
+ this.session = globalConfig.session || this.session;
379
390
  this.store = globalConfig.store || this.store;
380
391
  this.crossOriginWhitelist = globalConfig.crossOriginWhitelist || this.crossOriginWhitelist;
381
392
  this.applicationRootUrl = container.lookup('router:main').get('rootURL') || '/';
@@ -386,9 +397,6 @@ define("simple-auth/ember",
386
397
  ["./initializer"],
387
398
  function(__dependency1__) {
388
399
  "use strict";
389
- var global = (typeof window !== 'undefined') ? window : {},
390
- Ember = global.Ember;
391
-
392
400
  var initializer = __dependency1__["default"];
393
401
 
394
402
  Ember.onLoad('Ember.Application', function(Application) {
@@ -399,9 +407,6 @@ define("simple-auth/initializer",
399
407
  ["./setup","exports"],
400
408
  function(__dependency1__, __exports__) {
401
409
  "use strict";
402
- var global = (typeof window !== 'undefined') ? window : {},
403
- Ember = global.Ember;
404
-
405
410
  var setup = __dependency1__["default"];
406
411
 
407
412
  __exports__["default"] = {
@@ -415,9 +420,6 @@ define("simple-auth/mixins/application-route-mixin",
415
420
  ["./../configuration","exports"],
416
421
  function(__dependency1__, __exports__) {
417
422
  "use strict";
418
- var global = (typeof window !== 'undefined') ? window : {},
419
- Ember = global.Ember;
420
-
421
423
  var Configuration = __dependency1__["default"];
422
424
 
423
425
  /**
@@ -483,20 +485,22 @@ define("simple-auth/mixins/application-route-mixin",
483
485
  */
484
486
  beforeModel: function(transition) {
485
487
  this._super(transition);
486
- var _this = this;
487
- Ember.A([
488
- 'sessionAuthenticationSucceeded',
489
- 'sessionAuthenticationFailed',
490
- 'sessionInvalidationSucceeded',
491
- 'sessionInvalidationFailed',
492
- 'authorizationFailed'
493
- ]).forEach(function(event) {
494
- _this.get(Configuration.sessionPropertyName).on(event, function(error) {
495
- Array.prototype.unshift.call(arguments, event);
496
- var target = transition.isActive ? transition : _this;
497
- target.send.apply(target, arguments);
488
+ if (!this.get('_authEventListenersAssigned')) {
489
+ this.set('_authEventListenersAssigned', true);
490
+ var _this = this;
491
+ Ember.A([
492
+ 'sessionAuthenticationSucceeded',
493
+ 'sessionAuthenticationFailed',
494
+ 'sessionInvalidationSucceeded',
495
+ 'sessionInvalidationFailed',
496
+ 'authorizationFailed'
497
+ ]).forEach(function(event) {
498
+ _this.get(Configuration.sessionPropertyName).on(event, function(error) {
499
+ Array.prototype.unshift.call(arguments, event);
500
+ transition.send.apply(transition, arguments);
501
+ });
498
502
  });
499
- });
503
+ }
500
504
  },
501
505
 
502
506
  actions: {
@@ -631,9 +635,6 @@ define("simple-auth/mixins/authenticated-route-mixin",
631
635
  ["./../configuration","exports"],
632
636
  function(__dependency1__, __exports__) {
633
637
  "use strict";
634
- var global = (typeof window !== 'undefined') ? window : {},
635
- Ember = global.Ember;
636
-
637
638
  var Configuration = __dependency1__["default"];
638
639
 
639
640
  /**
@@ -689,9 +690,6 @@ define("simple-auth/mixins/authentication-controller-mixin",
689
690
  ["./../configuration","exports"],
690
691
  function(__dependency1__, __exports__) {
691
692
  "use strict";
692
- var global = (typeof window !== 'undefined') ? window : {},
693
- Ember = global.Ember;
694
-
695
693
  var Configuration = __dependency1__["default"];
696
694
 
697
695
  /**
@@ -740,9 +738,6 @@ define("simple-auth/mixins/login-controller-mixin",
740
738
  ["./../configuration","./authentication-controller-mixin","exports"],
741
739
  function(__dependency1__, __dependency2__, __exports__) {
742
740
  "use strict";
743
- var global = (typeof window !== 'undefined') ? window : {},
744
- Ember = global.Ember;
745
-
746
741
  var Configuration = __dependency1__["default"];
747
742
  var AuthenticationControllerMixin = __dependency2__["default"];
748
743
 
@@ -792,7 +787,7 @@ define("simple-auth/mixins/login-controller-mixin",
792
787
  authenticate: function() {
793
788
  var data = this.getProperties('identification', 'password');
794
789
  this.set('password', null);
795
- this._super(data);
790
+ return this._super(data);
796
791
  }
797
792
  }
798
793
  });
@@ -801,9 +796,6 @@ define("simple-auth/session",
801
796
  ["exports"],
802
797
  function(__exports__) {
803
798
  "use strict";
804
- var global = (typeof window !== 'undefined') ? window : {},
805
- Ember = global.Ember;
806
-
807
799
  /**
808
800
  __The session provides access to the current authentication state as well as
809
801
  any data the authenticator resolved with__ (see
@@ -914,6 +906,15 @@ define("simple-auth/session",
914
906
  @default null
915
907
  */
916
908
  store: null,
909
+ /**
910
+ The Ember.js container,
911
+
912
+ @property container
913
+ @type Container
914
+ @readOnly
915
+ @default null
916
+ */
917
+ container: null,
917
918
  /**
918
919
  Returns whether the session is currently authenticated.
919
920
 
@@ -934,14 +935,6 @@ define("simple-auth/session",
934
935
  */
935
936
  content: {},
936
937
 
937
- /**
938
- @method init
939
- @private
940
- */
941
- init: function() {
942
- this.bindToStoreEvents();
943
- },
944
-
945
938
  /**
946
939
  Authenticates the session with an `authenticator` and appropriate
947
940
  `options`. __This delegates the actual authentication work to the
@@ -993,6 +986,7 @@ define("simple-auth/session",
993
986
  @return {Ember.RSVP.Promise} A promise that resolves when the session was invalidated successfully
994
987
  */
995
988
  invalidate: function() {
989
+ Ember.assert('Session#invalidate requires the session to be authenticated', this.get('isAuthenticated'));
996
990
  var _this = this;
997
991
  return new Ember.RSVP.Promise(function(resolve, reject) {
998
992
  var authenticator = _this.container.lookup(_this.authenticator);
@@ -1037,6 +1031,7 @@ define("simple-auth/session",
1037
1031
  @private
1038
1032
  */
1039
1033
  setup: function(authenticator, content, trigger) {
1034
+ content = Ember.merge(Ember.merge({}, this.content), content);
1040
1035
  trigger = !!trigger && !this.get('isAuthenticated');
1041
1036
  this.beginPropertyChanges();
1042
1037
  this.setProperties({
@@ -1045,8 +1040,7 @@ define("simple-auth/session",
1045
1040
  content: content
1046
1041
  });
1047
1042
  this.bindToAuthenticatorEvents();
1048
- var data = Ember.$.extend({ authenticator: authenticator }, this.content);
1049
- this.store.replace(data);
1043
+ this.updateStore();
1050
1044
  this.endPropertyChanges();
1051
1045
  if (trigger) {
1052
1046
  this.trigger('sessionAuthenticationSucceeded');
@@ -1072,6 +1066,30 @@ define("simple-auth/session",
1072
1066
  }
1073
1067
  },
1074
1068
 
1069
+ /**
1070
+ @method setUnknownProperty
1071
+ @private
1072
+ */
1073
+ setUnknownProperty: function(key, value) {
1074
+ var result = this._super(key, value);
1075
+ this.updateStore();
1076
+ return result;
1077
+ },
1078
+
1079
+ /**
1080
+ @method updateStore
1081
+ @private
1082
+ */
1083
+ updateStore: function() {
1084
+ var data = this.content;
1085
+ if (!Ember.isEmpty(this.authenticator)) {
1086
+ data = Ember.merge({ authenticator: this.authenticator }, data);
1087
+ }
1088
+ if (!Ember.isEmpty(data)) {
1089
+ this.store.persist(data);
1090
+ }
1091
+ },
1092
+
1075
1093
  /**
1076
1094
  @method bindToAuthenticatorEvents
1077
1095
  @private
@@ -1108,7 +1126,7 @@ define("simple-auth/session",
1108
1126
  _this.clear(true);
1109
1127
  }
1110
1128
  });
1111
- }
1129
+ }.observes('store')
1112
1130
  });
1113
1131
  });
1114
1132
  define("simple-auth/setup",
@@ -1148,9 +1166,10 @@ define("simple-auth/setup",
1148
1166
  return crossOriginWhitelist.indexOf(urlOrigin) > -1;
1149
1167
  }
1150
1168
 
1151
- function registerStores(container) {
1169
+ function registerFactories(container) {
1152
1170
  container.register('simple-auth-session-store:local-storage', LocalStorage);
1153
1171
  container.register('simple-auth-session-store:ephemeral', Ephemeral);
1172
+ container.register('simple-auth-session:main', Session);
1154
1173
  }
1155
1174
 
1156
1175
  /**
@@ -1160,17 +1179,17 @@ define("simple-auth/setup",
1160
1179
  __exports__["default"] = function(container, application) {
1161
1180
  Configuration.load(container);
1162
1181
  application.deferReadiness();
1163
- registerStores(container);
1182
+ registerFactories(container);
1164
1183
 
1165
- var store = container.lookup(Configuration.store);
1166
- var session = Session.create({ store: store, container: container });
1167
- crossOriginWhitelist = Ember.A(Configuration.crossOriginWhitelist).map(function(origin) {
1168
- return extractLocationOrigin(origin);
1184
+ var store = container.lookup(Configuration.store);
1185
+ var session = container.lookup(Configuration.session);
1186
+ session.setProperties({ store: store, container: container });
1187
+ Ember.A(['controller', 'route']).forEach(function(component) {
1188
+ container.injection(component, Configuration.sessionPropertyName, Configuration.session);
1169
1189
  });
1170
1190
 
1171
- container.register('simple-auth-session:main', session, { instantiate: false });
1172
- Ember.A(['controller', 'route']).forEach(function(component) {
1173
- container.injection(component, Configuration.sessionPropertyName, 'simple-auth-session:main');
1191
+ crossOriginWhitelist = Ember.A(Configuration.crossOriginWhitelist).map(function(origin) {
1192
+ return extractLocationOrigin(origin);
1174
1193
  });
1175
1194
 
1176
1195
  if (!Ember.isEmpty(Configuration.authorizer)) {
@@ -1202,9 +1221,6 @@ define("simple-auth/stores/base",
1202
1221
  ["../utils/flat-objects-are-equal","exports"],
1203
1222
  function(__dependency1__, __exports__) {
1204
1223
  "use strict";
1205
- var global = (typeof window !== 'undefined') ? window : {},
1206
- Ember = global.Ember;
1207
-
1208
1224
  var flatObjectsAreEqual = __dependency1__["default"];
1209
1225
 
1210
1226
  /**
@@ -1243,7 +1259,8 @@ define("simple-auth/stores/base",
1243
1259
  */
1244
1260
 
1245
1261
  /**
1246
- Persists the `data` in the store.
1262
+ Persists the `data` in the store. This actually replaces all currently
1263
+ stored data.
1247
1264
 
1248
1265
  `Stores.Base`'s implementation does nothing.
1249
1266
 
@@ -1265,23 +1282,6 @@ define("simple-auth/stores/base",
1265
1282
  return {};
1266
1283
  },
1267
1284
 
1268
- /**
1269
- Replaces all data currently saved in the store with the specified `data`.
1270
-
1271
- `Stores.Base`'s implementation clears the store, then persists the
1272
- specified `data`. If the store's current content is equal to the specified
1273
- `data`, nothing is done.
1274
-
1275
- @method replace
1276
- @param {Object} data The data to replace the store's content with
1277
- */
1278
- replace: function(data) {
1279
- if (!flatObjectsAreEqual(data, this.restore())) {
1280
- this.clear();
1281
- this.persist(data);
1282
- }
1283
- },
1284
-
1285
1285
  /**
1286
1286
  Clears the store.
1287
1287
 
@@ -1297,9 +1297,6 @@ define("simple-auth/stores/ephemeral",
1297
1297
  ["./base","exports"],
1298
1298
  function(__dependency1__, __exports__) {
1299
1299
  "use strict";
1300
- var global = (typeof window !== 'undefined') ? window : {},
1301
- Ember = global.Ember;
1302
-
1303
1300
  var Base = __dependency1__["default"];
1304
1301
 
1305
1302
  /**
@@ -1333,7 +1330,7 @@ define("simple-auth/stores/ephemeral",
1333
1330
  @param {Object} data The data to persist
1334
1331
  */
1335
1332
  persist: function(data) {
1336
- this._data = Ember.$.extend(data, this._data);
1333
+ this._data = JSON.stringify(data || {});
1337
1334
  },
1338
1335
 
1339
1336
  /**
@@ -1343,7 +1340,7 @@ define("simple-auth/stores/ephemeral",
1343
1340
  @return {Object} All data currently persisted
1344
1341
  */
1345
1342
  restore: function() {
1346
- return Ember.$.extend({}, this._data);
1343
+ return JSON.parse(this._data) || {};
1347
1344
  },
1348
1345
 
1349
1346
  /**
@@ -1353,7 +1350,7 @@ define("simple-auth/stores/ephemeral",
1353
1350
  */
1354
1351
  clear: function() {
1355
1352
  delete this._data;
1356
- this._data = {};
1353
+ this._data = '{}';
1357
1354
  }
1358
1355
  });
1359
1356
  });
@@ -1361,9 +1358,6 @@ define("simple-auth/stores/local-storage",
1361
1358
  ["./base","../utils/flat-objects-are-equal","exports"],
1362
1359
  function(__dependency1__, __dependency2__, __exports__) {
1363
1360
  "use strict";
1364
- var global = (typeof window !== 'undefined') ? window : {},
1365
- Ember = global.Ember;
1366
-
1367
1361
  var Base = __dependency1__["default"];
1368
1362
  var flatObjectsAreEqual = __dependency2__["default"];
1369
1363
 
@@ -1382,20 +1376,13 @@ define("simple-auth/stores/local-storage",
1382
1376
  */
1383
1377
  __exports__["default"] = Base.extend({
1384
1378
  /**
1385
- The prefix to use for the store's keys so they can be distinguished from
1386
- others.
1379
+ The key the store stores the data in.
1387
1380
 
1388
- @property keyPrefix
1381
+ @property key
1389
1382
  @type String
1390
- @default 'ember_simple_auth:'
1383
+ @default 'ember_simple_auth:session'
1391
1384
  */
1392
- keyPrefix: 'ember_simple_auth:',
1393
-
1394
- /**
1395
- @property _triggerChangeEventTimeout
1396
- @private
1397
- */
1398
- _triggerChangeEventTimeout: null,
1385
+ key: 'ember_simple_auth:session',
1399
1386
 
1400
1387
  /**
1401
1388
  @method init
@@ -1412,10 +1399,8 @@ define("simple-auth/stores/local-storage",
1412
1399
  @param {Object} data The data to persist
1413
1400
  */
1414
1401
  persist: function(data) {
1415
- for (var property in data) {
1416
- var key = this.buildStorageKey(property);
1417
- localStorage.setItem(key, data[property]);
1418
- }
1402
+ data = JSON.stringify(data || {});
1403
+ localStorage.setItem(this.key, data);
1419
1404
  this._lastData = this.restore();
1420
1405
  },
1421
1406
 
@@ -1427,13 +1412,8 @@ define("simple-auth/stores/local-storage",
1427
1412
  @return {Object} All data currently persisted in the `localStorage`
1428
1413
  */
1429
1414
  restore: function() {
1430
- var _this = this;
1431
- var data = {};
1432
- this.knownKeys().forEach(function(key) {
1433
- var originalKey = key.replace(_this.keyPrefix, '');
1434
- data[originalKey] = localStorage.getItem(key);
1435
- });
1436
- return data;
1415
+ var data = localStorage.getItem(this.key);
1416
+ return JSON.parse(data) || {};
1437
1417
  },
1438
1418
 
1439
1419
  /**
@@ -1443,35 +1423,10 @@ define("simple-auth/stores/local-storage",
1443
1423
  @method clear
1444
1424
  */
1445
1425
  clear: function() {
1446
- this.knownKeys().forEach(function(key) {
1447
- localStorage.removeItem(key);
1448
- });
1426
+ localStorage.removeItem(this.key);
1449
1427
  this._lastData = null;
1450
1428
  },
1451
1429
 
1452
- /**
1453
- @method buildStorageKey
1454
- @private
1455
- */
1456
- buildStorageKey: function(property) {
1457
- return this.keyPrefix + property;
1458
- },
1459
-
1460
- /**
1461
- @method knownKeys
1462
- @private
1463
- */
1464
- knownKeys: function(callback) {
1465
- var keys = Ember.A([]);
1466
- for (var i = 0, l = localStorage.length; i < l; i++) {
1467
- var key = localStorage.key(i);
1468
- if (key.indexOf(this.keyPrefix) === 0) {
1469
- keys.push(key);
1470
- }
1471
- }
1472
- return keys;
1473
- },
1474
-
1475
1430
  /**
1476
1431
  @method bindToStorageEvents
1477
1432
  @private
@@ -1482,10 +1437,7 @@ define("simple-auth/stores/local-storage",
1482
1437
  var data = _this.restore();
1483
1438
  if (!flatObjectsAreEqual(data, _this._lastData)) {
1484
1439
  _this._lastData = data;
1485
- Ember.run.cancel(_this._triggerChangeEventTimeout);
1486
- _this._triggerChangeEventTimeout = Ember.run.next(_this, function() {
1487
- this.trigger('sessionDataUpdated', data);
1488
- });
1440
+ _this.trigger('sessionDataUpdated', data);
1489
1441
  }
1490
1442
  });
1491
1443
  }
@@ -1591,4 +1543,6 @@ global.SimpleAuth = {
1591
1543
  };
1592
1544
 
1593
1545
  requireModule('simple-auth/ember');
1546
+
1547
+ Ember.libraries.register('Ember Simple Auth', '0.6.4');
1594
1548
  })((typeof global !== 'undefined') ? global : window);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember_simple_auth-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - frederik dudzik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-10 00:00:00.000000000 Z
11
+ date: 2014-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,7 @@ files:
66
66
  - vendor/assets/javascripts/ember-simple-auth-cookie-store.js
67
67
  - vendor/assets/javascripts/ember-simple-auth-devise.js
68
68
  - vendor/assets/javascripts/ember-simple-auth-oauth2.js
69
+ - vendor/assets/javascripts/ember-simple-auth-testing.js
69
70
  - vendor/assets/javascripts/ember-simple-auth-torii.js
70
71
  - vendor/assets/javascripts/ember-simple-auth.js
71
72
  homepage: https://github.com/doodzik/ember_simple_auth-rails