ember_simple_auth-rails 0.3.1 → 0.4.0

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: 605845d85130ca07eae4a17a001b477882dd3a4e
4
- data.tar.gz: 23a99b483687610f7585778b210d6209854f3cc7
3
+ metadata.gz: 07741959b67e856d702b434adb200d3f44a5fe0f
4
+ data.tar.gz: 5826b6b4444b4e1fd43b2a87ba1ea8b8e71f6072
5
5
  SHA512:
6
- metadata.gz: b1849325e60e55838eed85a31518ab6ff1fd5daead223d23db22da875ae2d404d74d0ea325fe5200459e832efc1d8c4940332dea637bc7a65661db0163569a9b
7
- data.tar.gz: be4eb68655dde906408d8f759dee565631e3cb220e4c737d312d162220d87e88a9a6de8663ef24174225b3f975e35a20fd2a25e0f6c027d0558292b920ec31cf
6
+ metadata.gz: 81bfc6433b42d4b008b1b82f63415cc76d27f614fac0421b5916f29f65b0787413a9b93b016498290307aabfa184b767e9fdf5216f3e0a48dfe4e74caeac88ba
7
+ data.tar.gz: 95aad7c271b5adafb06213c1dca97bfeae3cdd475568ae93e5095d887bd38eeff970403d9941a1b1116b7ebc85f3fba7957224dbb67f3ac8cdefe475f70d24aa
@@ -1,5 +1,5 @@
1
1
  module EmberSimpleAuth
2
2
  module Rails
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -82,8 +82,8 @@ define("ember-simple-auth-cookie-store/stores/cookie",
82
82
  This store will trigger the `'updated'` event when any of its cookies is
83
83
  changed from another tab or window.
84
84
 
85
- _The factory for this store is registered as `'session-store:cookie'` in
86
- Ember's container.
85
+ _The factory for this store is registered as
86
+ `'ember-simple-auth-session-store:cookie'` in Ember's container._
87
87
 
88
88
  @class Cookie
89
89
  @namespace Stores
@@ -220,6 +220,6 @@ define("ember-simple-auth-cookie-store/stores/cookie",
220
220
  global.Ember.SimpleAuth.Stores.Cookie = requireModule('ember-simple-auth-cookie-store').default;
221
221
 
222
222
  global.Ember.SimpleAuth.initializeExtension(function(container, application, options) {
223
- container.register('session-store:cookie', global.Ember.SimpleAuth.Stores.Cookie);
223
+ container.register('ember-simple-auth-session-store:cookie', global.Ember.SimpleAuth.Stores.Cookie);
224
224
  });
225
225
  })((typeof global !== 'undefined') ? global : window);
@@ -80,8 +80,8 @@ define("ember-simple-auth-devise/authenticators/devise",
80
80
  see the README and
81
81
  [discussion here](https://gist.github.com/josevalim/fb706b1e933ef01e4fb6).
82
82
 
83
- _The factory for this authenticator is registered as `'authenticator:devise'`
84
- in Ember's container._
83
+ _The factory for this authenticator is registered as
84
+ `'ember-simple-auth-authenticator:devise'` in Ember's container._
85
85
 
86
86
  @class Devise
87
87
  @namespace Authenticators
@@ -98,6 +98,15 @@ define("ember-simple-auth-devise/authenticators/devise",
98
98
  */
99
99
  serverTokenEndpoint: '/users/sign_in',
100
100
 
101
+ /**
102
+ The devise resource name
103
+
104
+ @property resourceName
105
+ @type String
106
+ @default 'user'
107
+ */
108
+ resourceName: 'user',
109
+
101
110
  /**
102
111
  Restores the session from a set of session properties; __will return a
103
112
  resolving promise when there's a non-empty `auth_token` and a non-empty
@@ -132,7 +141,8 @@ define("ember-simple-auth-devise/authenticators/devise",
132
141
  authenticate: function(credentials) {
133
142
  var _this = this;
134
143
  return new Ember.RSVP.Promise(function(resolve, reject) {
135
- var data = {
144
+ var data = {};
145
+ data[_this.resourceName] = {
136
146
  email: credentials.identification,
137
147
  password: credentials.password
138
148
  };
@@ -167,11 +177,13 @@ define("ember-simple-auth-devise/authenticators/devise",
167
177
  Ember.Logger.warn('Credentials are transmitted via an insecure connection - use HTTPS to keep them secure.');
168
178
  }
169
179
  return Ember.$.ajax({
170
- url: this.serverTokenEndpoint,
171
- type: 'POST',
172
- data: data,
173
- dataType: 'json',
174
- contentType: 'application/x-www-form-urlencoded'
180
+ url: this.serverTokenEndpoint,
181
+ type: 'POST',
182
+ data: data,
183
+ dataType: 'json',
184
+ beforeSend: function(xhr, settings) {
185
+ xhr.setRequestHeader('Accept', settings.accepts.json);
186
+ }
175
187
  });
176
188
  }
177
189
  });
@@ -187,16 +199,15 @@ define("ember-simple-auth-devise/authorizers/devise",
187
199
 
188
200
  /**
189
201
  Authenticator that works with the Ruby gem
190
- [Devise](https://github.com/plataformatec/devise) by adding `auth-token` and
191
- `auth-email` headers to requests.
202
+ [Devise](https://github.com/plataformatec/devise) by sending the `user_token`
203
+ and `user_email` properties from the session in the `Authorization` header.
192
204
 
193
205
  __As token authentication is not actually part of devise anymore, the server
194
206
  needs to implement some customizations__ to work with this authenticator -
195
- see the README and
196
- [discussion here](https://gist.github.com/josevalim/fb706b1e933ef01e4fb6).
207
+ see the README for more information.
197
208
 
198
- _The factory for this authorizer is registered as `'authorizer:devise'` in
199
- Ember's container._
209
+ _The factory for this authorizer is registered as
210
+ `'ember-simple-auth-authorizer:devise'` in Ember's container._
200
211
 
201
212
  @class Devise
202
213
  @namespace Authorizers
@@ -204,12 +215,11 @@ define("ember-simple-auth-devise/authorizers/devise",
204
215
  */
205
216
  var Devise = Ember.SimpleAuth.Authorizers.Base.extend({
206
217
  /**
207
- Authorizes an XHR request by sending the `auth_token` and `auth_email`
208
- properties from the session in custom headers:
218
+ Authorizes an XHR request by sending the `user_token` and `user_email`
219
+ properties from the session in the `Authorization` header:
209
220
 
210
221
  ```
211
- auth-token: <auth_token>
212
- auth-email: <auth_email>
222
+ Authorization: Token token="<user_token>", user_email="<user_email>"
213
223
  ```
214
224
 
215
225
  @method authorize
@@ -218,14 +228,14 @@ define("ember-simple-auth-devise/authorizers/devise",
218
228
  */
219
229
 
220
230
  authorize: function(jqXHR, requestOptions) {
221
- var authToken = this.get('session.auth_token');
222
- var authEmail = this.get('session.auth_email');
223
- if (this.get('session.isAuthenticated') && !Ember.isEmpty(authToken) && !Ember.isEmpty(authEmail)) {
231
+ var userToken = this.get('session.user_token');
232
+ var userEmail = this.get('session.user_email');
233
+ if (this.get('session.isAuthenticated') && !Ember.isEmpty(userToken) && !Ember.isEmpty(userEmail)) {
224
234
  if (!Ember.SimpleAuth.Utils.isSecureUrl(requestOptions.url)) {
225
235
  Ember.Logger.warn('Credentials are transmitted via an insecure connection - use HTTPS to keep them secure.');
226
236
  }
227
- jqXHR.setRequestHeader('auth-token', authToken);
228
- jqXHR.setRequestHeader('auth-email', authEmail);
237
+ var authData = 'token="' + userToken + '", user_email="' + userEmail + '"';
238
+ jqXHR.setRequestHeader('Authorization', 'Token ' + authData);
229
239
  }
230
240
  }
231
241
  });
@@ -238,7 +248,7 @@ global.Ember.SimpleAuth.Authenticators.Devise = devise.Authenticator;
238
248
  global.Ember.SimpleAuth.Authorizers.Devise = devise.Authorizer;
239
249
 
240
250
  global.Ember.SimpleAuth.initializeExtension(function(container, application, options) {
241
- container.register('authorizer:devise', global.Ember.SimpleAuth.Authorizers.Devise);
242
- container.register('authenticator:devise', global.Ember.SimpleAuth.Authenticators.Devise);
251
+ container.register('ember-simple-auth-authorizer:devise', global.Ember.SimpleAuth.Authorizers.Devise);
252
+ container.register('ember-simple-auth-authenticator:devise', global.Ember.SimpleAuth.Authenticators.Devise);
243
253
  });
244
254
  })((typeof global !== 'undefined') ? global : window);
@@ -80,7 +80,8 @@ define("ember-simple-auth-oauth2/authenticators/oauth2",
80
80
  will trigger the `'updated'` event each time the token was refreshed.
81
81
 
82
82
  _The factory for this authenticator is registered as
83
- `'authenticator:oauth2-password-grant'` in Ember's container._
83
+ `'ember-simple-auth-authenticator:oauth2-password-grant'` in Ember's
84
+ container._
84
85
 
85
86
  @class OAuth2
86
87
  @namespace Authenticators
@@ -298,7 +299,7 @@ define("ember-simple-auth-oauth2/authorizers/oauth2",
298
299
  `Authorization` header.
299
300
 
300
301
  _The factory for this authorizer is registered as
301
- `'authorizer:oauth2-bearer'` in Ember's container._
302
+ `'ember-simple-auth-authorizer:oauth2-bearer'` in Ember's container._
302
303
 
303
304
  @class OAuth2
304
305
  @namespace Authorizers
@@ -336,7 +337,7 @@ global.Ember.SimpleAuth.Authenticators.OAuth2 = oauth2.Authenticator;
336
337
  global.Ember.SimpleAuth.Authorizers.OAuth2 = oauth2.Authorizer;
337
338
 
338
339
  global.Ember.SimpleAuth.initializeExtension(function(container, application, options) {
339
- container.register('authorizer:oauth2-bearer', global.Ember.SimpleAuth.Authorizers.OAuth2);
340
- container.register('authenticator:oauth2-password-grant', global.Ember.SimpleAuth.Authenticators.OAuth2);
340
+ container.register('ember-simple-auth-authorizer:oauth2-bearer', global.Ember.SimpleAuth.Authorizers.OAuth2);
341
+ container.register('ember-simple-auth-authenticator:oauth2-password-grant', global.Ember.SimpleAuth.Authenticators.OAuth2);
341
342
  });
342
343
  })((typeof global !== 'undefined') ? global : window);
@@ -340,9 +340,8 @@ define("ember-simple-auth/core",
340
340
  'sessionInvalidationSucceeded',
341
341
  'sessionInvalidationFailed'
342
342
  ]).forEach(function(event) {
343
- session.on(event, function() {
344
- Array.prototype.unshift.call(arguments, event);
345
- router.send.apply(router, arguments);
343
+ session.on(event, function(error) {
344
+ router.send(event, error);
346
345
  });
347
346
  });
348
347
  return session;
@@ -381,13 +380,26 @@ define("ember-simple-auth/core",
381
380
  */
382
381
  routeAfterAuthentication: 'index',
383
382
 
383
+ /**
384
+ The name of the property that the session is injected with into routes and
385
+ controllers; should be set through
386
+ [Ember.SimpleAuth.setup](#Ember-SimpleAuth-setup).
387
+
388
+ @property sessionPropertyName
389
+ @readOnly
390
+ @static
391
+ @type String
392
+ @default 'session'
393
+ */
394
+ sessionPropertyName: 'session',
395
+
384
396
  /**
385
397
  @property applicationRootUrl
386
398
  @static
387
399
  @private
388
400
  @type String
389
401
  */
390
- applicationRootUrl: null,
402
+ applicationRootUrl: null
391
403
  };
392
404
 
393
405
  /**
@@ -411,6 +423,7 @@ define("ember-simple-auth/core",
411
423
  @param {Object} options
412
424
  @param {String} [options.authorizerFactory] The authorizer factory to use as it is registered with Ember's container, see [Ember's API docs](http://emberjs.com/api/classes/Ember.Application.html#method_register); when the application does not interact with a server that requires authorized requests, no auzthorizer is needed
413
425
  @param {Object} [options.storeFactory] The store factory to use as it is registered with Ember's container, see [Ember's API docs](http://emberjs.com/api/classes/Ember.Application.html#method_register) - defaults to `session-stores:local-storage`
426
+ @param {Object} [options.sessionPropertyName] The name for the property that the session is injected with into routes and controllers - defaults to `session`
414
427
  @param {String} [options.authenticationRoute] route to transition to for authentication - defaults to `'login'`
415
428
  @param {String} [options.routeAfterAuthentication] route to transition to after successful authentication - defaults to `'index'`
416
429
  @param {Array[String]} [options.crossOriginWhitelist] Ember.SimpleAuth will never authorize requests going to a different origin than the one the Ember.js application was loaded from; to explicitely enable authorization for additional origins, whitelist those origins - defaults to `[]` _(beware that origins consist of protocol, host and port (port can be left out when it is 80 for HTTP or 443 for HTTPS))_
@@ -425,18 +438,19 @@ define("ember-simple-auth/core",
425
438
  options = options || {};
426
439
  Configuration.routeAfterAuthentication = options.routeAfterAuthentication || Configuration.routeAfterAuthentication;
427
440
  Configuration.authenticationRoute = options.authenticationRoute || Configuration.authenticationRoute;
441
+ Configuration.sessionPropertyName = options.sessionPropertyName || Configuration.sessionPropertyName;
428
442
  Configuration.applicationRootUrl = container.lookup('router:main').get('rootURL') || '/';
429
443
  crossOriginWhitelist = Ember.A(options.crossOriginWhitelist || []).map(function(origin) {
430
444
  return extractLocationOrigin(origin);
431
445
  });
432
446
 
433
- options.storeFactory = options.storeFactory || 'session-store:local-storage';
447
+ options.storeFactory = options.storeFactory || 'ember-simple-auth-session-store:local-storage';
434
448
  var store = container.lookup(options.storeFactory);
435
449
  var session = setupSession(store, container);
436
450
 
437
- container.register('session:main', session, { instantiate: false });
451
+ container.register('ember-simple-auth-session:main', session, { instantiate: false });
438
452
  Ember.A(['controller', 'route']).forEach(function(component) {
439
- container.injection(component, 'session', 'session:main');
453
+ container.injection(component, Configuration.sessionPropertyName, 'ember-simple-auth-session:main');
440
454
  });
441
455
 
442
456
  if (!Ember.isEmpty(options.authorizerFactory)) {
@@ -564,10 +578,10 @@ define("ember-simple-auth/mixins/application_route_mixin",
564
578
  @method actions.sessionAuthenticationSucceeded
565
579
  */
566
580
  sessionAuthenticationSucceeded: function() {
567
- var attemptedTransition = this.get('session.attemptedTransition');
581
+ var attemptedTransition = this.get(Configuration.sessionPropertyName).get('attemptedTransition');
568
582
  if (attemptedTransition) {
569
583
  attemptedTransition.retry();
570
- this.set('session.attemptedTransition', null);
584
+ this.get(Configuration.sessionPropertyName).set('attemptedTransition', null);
571
585
  } else {
572
586
  this.transitionTo(Configuration.routeAfterAuthentication);
573
587
  }
@@ -606,7 +620,7 @@ define("ember-simple-auth/mixins/application_route_mixin",
606
620
  @method actions.invalidateSession
607
621
  */
608
622
  invalidateSession: function() {
609
- this.get('session').invalidate();
623
+ this.get(Configuration.sessionPropertyName).invalidate();
610
624
  },
611
625
 
612
626
  /**
@@ -643,7 +657,7 @@ define("ember-simple-auth/mixins/application_route_mixin",
643
657
  @method actions.authorizationFailed
644
658
  */
645
659
  authorizationFailed: function() {
646
- this.get('session').invalidate();
660
+ this.get(Configuration.sessionPropertyName).invalidate();
647
661
  },
648
662
 
649
663
  /**
@@ -662,12 +676,14 @@ define("ember-simple-auth/mixins/application_route_mixin",
662
676
  __exports__.ApplicationRouteMixin = ApplicationRouteMixin;
663
677
  });
664
678
  define("ember-simple-auth/mixins/authenticated_route_mixin",
665
- ["exports"],
666
- function(__exports__) {
679
+ ["./../core","exports"],
680
+ function(__dependency1__, __exports__) {
667
681
  "use strict";
668
682
  var global = (typeof window !== 'undefined') ? window : {},
669
683
  Ember = global.Ember;
670
684
 
685
+ var Configuration = __dependency1__.Configuration;
686
+
671
687
  /**
672
688
  The mixin for routes that require the session to be authenticated in order to
673
689
  be accessible. Including this mixin in a route automatically adds a hook that
@@ -703,9 +719,9 @@ define("ember-simple-auth/mixins/authenticated_route_mixin",
703
719
  @param {Transition} transition The transition that lead to this route
704
720
  */
705
721
  beforeModel: function(transition) {
706
- if (!this.get('session.isAuthenticated')) {
722
+ if (!this.get(Configuration.sessionPropertyName).get('isAuthenticated')) {
707
723
  transition.abort();
708
- this.set('session.attemptedTransition', transition);
724
+ this.get(Configuration.sessionPropertyName).set('attemptedTransition', transition);
709
725
  transition.send('authenticateSession');
710
726
  }
711
727
  }
@@ -714,12 +730,14 @@ define("ember-simple-auth/mixins/authenticated_route_mixin",
714
730
  __exports__.AuthenticatedRouteMixin = AuthenticatedRouteMixin;
715
731
  });
716
732
  define("ember-simple-auth/mixins/authentication_controller_mixin",
717
- ["exports"],
718
- function(__exports__) {
733
+ ["./../core","exports"],
734
+ function(__dependency1__, __exports__) {
719
735
  "use strict";
720
736
  var global = (typeof window !== 'undefined') ? window : {},
721
737
  Ember = global.Ember;
722
738
 
739
+ var Configuration = __dependency1__.Configuration;
740
+
723
741
  /**
724
742
  The mixin for the controller that handles the `authenticationRoute` specified
725
743
  in [Ember.SimpleAuth.setup](#Ember-SimpleAuth-setup)). It provides the
@@ -751,7 +769,7 @@ define("ember-simple-auth/mixins/authentication_controller_mixin",
751
769
  @param {Object} options Any options the auhtenticator needs to authenticate the session
752
770
  */
753
771
  authenticate: function(options) {
754
- this.get('session').authenticate(this.get('authenticatorFactory'), options);
772
+ this.get(Configuration.sessionPropertyName).authenticate(this.get('authenticatorFactory'), options);
755
773
  }
756
774
  }
757
775
  });
@@ -759,13 +777,14 @@ define("ember-simple-auth/mixins/authentication_controller_mixin",
759
777
  __exports__.AuthenticationControllerMixin = AuthenticationControllerMixin;
760
778
  });
761
779
  define("ember-simple-auth/mixins/login_controller_mixin",
762
- ["./authentication_controller_mixin","exports"],
763
- function(__dependency1__, __exports__) {
780
+ ["./../core","./authentication_controller_mixin","exports"],
781
+ function(__dependency1__, __dependency2__, __exports__) {
764
782
  "use strict";
765
783
  var global = (typeof window !== 'undefined') ? window : {},
766
784
  Ember = global.Ember;
767
785
 
768
- var AuthenticationControllerMixin = __dependency1__.AuthenticationControllerMixin;
786
+ var Configuration = __dependency1__.Configuration;
787
+ var AuthenticationControllerMixin = __dependency2__.AuthenticationControllerMixin;
769
788
 
770
789
  /**
771
790
  The mixin to use with the controller that handles the `authenticationRoute`
@@ -831,7 +850,7 @@ define("ember-simple-auth/session",
831
850
  [Ember.SimpleAuth.Authenticators.Base#authenticate](#Ember-SimpleAuth-Authenticators-Base-authenticate)).
832
851
  It is created when Ember.SimpleAuth is set up (see
833
852
  [Ember.SimpleAuth.setup](#Ember-SimpleAuth-setup)) and __injected into all
834
- models, controllers, routes and views so that all parts of the application
853
+ controllers and routes so that these parts of the application
835
854
  can always access the current authentication state and other data__,
836
855
  depending on the used authenticator and whether the session is actually
837
856
  authenticated (see
@@ -920,9 +939,9 @@ define("ember-simple-auth/session",
920
939
  },
921
940
 
922
941
  /**
923
- Authentices the session with an `authenticator` and appropriate `options`.
924
- __This delegates the actual authentication work to the `authenticator`__
925
- and handles the returned promise accordingly (see
942
+ Authenticates the session with an `authenticator` and appropriate
943
+ `options`. __This delegates the actual authentication work to the
944
+ `authenticator`__ and handles the returned promise accordingly (see
926
945
  [Ember.SimpleAuth.Authenticators.Base#authenticate](#Ember-SimpleAuth-Authenticators-Base-authenticate)).
927
946
  All data the authenticator resolves with will be saved in the session.
928
947
 
@@ -937,6 +956,7 @@ define("ember-simple-auth/session",
937
956
  @return {Ember.RSVP.Promise} A promise that resolves when the session was authenticated successfully
938
957
  */
939
958
  authenticate: function(authenticatorFactory, options) {
959
+ Ember.assert('Session#authenticate requires the authenticator factory to be specified, was ' + authenticatorFactory, !Ember.isEmpty(authenticatorFactory));
940
960
  var _this = this;
941
961
  return new Ember.RSVP.Promise(function(resolve, reject) {
942
962
  _this.container.lookup(authenticatorFactory).authenticate(options).then(function(content) {
@@ -1100,8 +1120,8 @@ define("ember-simple-auth/stores",
1100
1120
  };
1101
1121
 
1102
1122
  var registerStores = function(container) {
1103
- container.register('session-store:local-storage', LocalStorage);
1104
- container.register('session-store:ephemeral', Ephemeral);
1123
+ container.register('ember-simple-auth-session-store:local-storage', LocalStorage);
1124
+ container.register('ember-simple-auth-session-store:ephemeral', Ephemeral);
1105
1125
  };
1106
1126
 
1107
1127
  __exports__.registerStores = registerStores;
@@ -1209,8 +1229,8 @@ define("ember-simple-auth/stores/ephemeral",
1209
1229
 
1210
1230
  __This store is mainly useful for testing.__
1211
1231
 
1212
- _The factory for this store is registered as `'session-store:ephemeral'` in
1213
- Ember's container._
1232
+ _The factory for this store is registered as
1233
+ `'ember-simple-auth-session-store:ephemeral'` in Ember's container._
1214
1234
 
1215
1235
  @class Ephemeral
1216
1236
  @namespace Stores
@@ -1274,8 +1294,8 @@ define("ember-simple-auth/stores/local_storage",
1274
1294
  This store will trigger the `'updated'` event when any of the keys it manages
1275
1295
  is changed from another tab or window.
1276
1296
 
1277
- _The factory for this store is registered as `'session-store:local-storage'`
1278
- in Ember's container._
1297
+ _The factory for this store is registered as
1298
+ `'ember-simple-auth-session-store:local-storage'` in Ember's container._
1279
1299
 
1280
1300
  @class LocalStorage
1281
1301
  @namespace Stores
@@ -1447,7 +1467,7 @@ define("ember-simple-auth/utils/is_secure_url",
1447
1467
  */
1448
1468
  var isSecureUrl = function(url) {
1449
1469
  var link = document.createElement('a');
1450
- link.href = location;
1470
+ link.href = url;
1451
1471
  link.href = link.href;
1452
1472
  return link.protocol == 'https:';
1453
1473
  };
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.3.1
4
+ version: 0.4.0
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-04-15 00:00:00.000000000 Z
11
+ date: 2014-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler