ember_simple_auth-rails 0.6.2 → 0.6.3

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: 53aea33dad689448357067597038c51240d0eaa9
4
- data.tar.gz: c2e08042ab35453d753bb938ec8d5ffd7b4c60ca
3
+ metadata.gz: a6114507e7e5eeef52db1098b98f10d9dc483d29
4
+ data.tar.gz: 97a46d0071cce71416c5c290d7b45ba939f0b294
5
5
  SHA512:
6
- metadata.gz: 62faee61aaebf1eeddafd9222c79bcf0231b64d4e589e7ce505e8140d40f08f698b99b54a69436d65bb508f24269bb9b57b6fefe505622df2bbbbf099f5d25f9
7
- data.tar.gz: 027726929408bdd1ef45a0586e943f14ce1f8aff932ed2c74007374f2d2877d480787dd60df6be0168df98a10675aeaaa268c38afc707f29093c2827708ec9e9
6
+ metadata.gz: e721d44e48b6e4155d5f23afeb7cd7d3e3b51bcbb98fd88c25b62886230763af840d320ece40eb49555cd2a0a31158fe7f6b27e1e2cea9de6bb15873de99c666
7
+ data.tar.gz: 91e92b317511b1a7eaefabc052cbb347b1ed52e7607e2122520e48a623bdb7459d2f3f87c45b9d3cdb81bfe20d2ffb8f4e54c5d6b3a95c51945e2c013d8e9f64
@@ -1,5 +1,5 @@
1
1
  module EmberSimpleAuth
2
2
  module Rails
3
- VERSION = "0.6.2"
3
+ VERSION = "0.6.3"
4
4
  end
5
5
  end
@@ -110,6 +110,25 @@ define("simple-auth-oauth2/authenticators/oauth2",
110
110
  */
111
111
  serverTokenEndpoint: '/token',
112
112
 
113
+ /**
114
+ The endpoint on the server the authenticator uses to revoke tokens. Only
115
+ set this if the server actually supports token revokation.
116
+
117
+ This value can be configured via the global environment object:
118
+
119
+ ```js
120
+ window.ENV = window.ENV || {};
121
+ window.ENV['simple-auth-oauth2'] = {
122
+ serverTokenRevokationEndpoint: '/some/custom/endpoint'
123
+ }
124
+ ```
125
+
126
+ @property serverTokenRevokationEndpoint
127
+ @type String
128
+ @default null
129
+ */
130
+ serverTokenRevokationEndpoint: null,
131
+
113
132
  /**
114
133
  Sets whether the authenticator automatically refreshes access tokens.
115
134
 
@@ -139,9 +158,10 @@ define("simple-auth-oauth2/authenticators/oauth2",
139
158
  @private
140
159
  */
141
160
  init: function() {
142
- var globalConfig = getGlobalConfig('simple-auth-oauth2');
143
- this.serverTokenEndpoint = globalConfig.serverTokenEndpoint || this.serverTokenEndpoint;
144
- this.refreshAccessTokens = globalConfig.refreshAccessTokens || this.refreshAccessTokens;
161
+ var globalConfig = getGlobalConfig('simple-auth-oauth2');
162
+ this.serverTokenEndpoint = globalConfig.serverTokenEndpoint || this.serverTokenEndpoint;
163
+ this.serverTokenRevokationEndpoint = globalConfig.serverTokenRevokationEndpoint || this.serverTokenRevokationEndpoint;
164
+ this.refreshAccessTokens = globalConfig.refreshAccessTokens || this.refreshAccessTokens;
145
165
  },
146
166
 
147
167
  /**
@@ -204,7 +224,7 @@ define("simple-auth-oauth2/authenticators/oauth2",
204
224
  var _this = this;
205
225
  return new Ember.RSVP.Promise(function(resolve, reject) {
206
226
  var data = { grant_type: 'password', username: credentials.identification, password: credentials.password };
207
- _this.makeRequest(data).then(function(response) {
227
+ _this.makeRequest(_this.serverTokenEndpoint, data).then(function(response) {
208
228
  Ember.run(function() {
209
229
  var expiresAt = _this.absolutizeExpirationTime(response.expires_in);
210
230
  _this.scheduleAccessTokenRefresh(response.expires_in, expiresAt, response.refresh_token);
@@ -223,17 +243,38 @@ define("simple-auth-oauth2/authenticators/oauth2",
223
243
  promise.
224
244
 
225
245
  @method invalidate
246
+ @param {Object} data The data of the session to be invalidated
226
247
  @return {Ember.RSVP.Promise} A resolving promise
227
248
  */
228
- invalidate: function() {
229
- Ember.run.cancel(this._refreshTokenTimeout);
230
- delete this._refreshTokenTimeout;
231
- return new Ember.RSVP.resolve();
249
+ invalidate: function(data) {
250
+ var _this = this;
251
+ function success(resolve) {
252
+ Ember.run.cancel(_this._refreshTokenTimeout);
253
+ delete _this._refreshTokenTimeout;
254
+ resolve();
255
+ }
256
+ return new Ember.RSVP.Promise(function(resolve, reject) {
257
+ if (!Ember.isEmpty(_this.serverTokenRevokationEndpoint)) {
258
+ var requests = [];
259
+ Ember.A(['access_token', 'refresh_token']).forEach(function(tokenType) {
260
+ if (!Ember.isEmpty(data[tokenType])) {
261
+ requests.push(_this.makeRequest(_this.serverTokenRevokationEndpoint, {
262
+ token_type_hint: tokenType, token: data[tokenType]
263
+ }));
264
+ }
265
+ });
266
+ Ember.$.when.apply(Ember.$, requests).always(function(responses) {
267
+ success(resolve);
268
+ });
269
+ } else {
270
+ success(resolve);
271
+ }
272
+ });
232
273
  },
233
274
 
234
275
  /**
235
- Sends an `AJAX` request to the `serverTokenEndpoint`. This will always be a
236
- _"POST"_ request with content type _"application/x-www-form-urlencoded"_ as
276
+ Sends an `AJAX` request to the `url`. This will always be a _"POST"_
277
+ request with content type _"application/x-www-form-urlencoded"_ as
237
278
  specified in [RFC 6749](http://tools.ietf.org/html/rfc6749).
238
279
 
239
280
  This method is not meant to be used directly but serves as an extension
@@ -241,16 +282,17 @@ define("simple-auth-oauth2/authenticators/oauth2",
241
282
  [RFC 6749, section 2.3](http://tools.ietf.org/html/rfc6749#section-2.3)).
242
283
 
243
284
  @method makeRequest
285
+ @param {Object} url The url to send the request to
244
286
  @param {Object} data The data to send with the request, e.g. username and password or the refresh token
245
287
  @return {Deferred object} A Deferred object (see [the jQuery docs](http://api.jquery.com/category/deferred-object/)) that is compatible to Ember.RSVP.Promise; will resolve if the request succeeds, reject otherwise
246
288
  @protected
247
289
  */
248
- makeRequest: function(data) {
249
- if (!isSecureUrl(this.serverTokenEndpoint)) {
290
+ makeRequest: function(url, data) {
291
+ if (!isSecureUrl(url)) {
250
292
  Ember.Logger.warn('Credentials are transmitted via an insecure connection - use HTTPS to keep them secure.');
251
293
  }
252
294
  return Ember.$.ajax({
253
- url: this.serverTokenEndpoint,
295
+ url: url,
254
296
  type: 'POST',
255
297
  data: data,
256
298
  dataType: 'json',
@@ -288,7 +330,7 @@ define("simple-auth-oauth2/authenticators/oauth2",
288
330
  var _this = this;
289
331
  var data = { grant_type: 'refresh_token', refresh_token: refreshToken };
290
332
  return new Ember.RSVP.Promise(function(resolve, reject) {
291
- _this.makeRequest(data).then(function(response) {
333
+ _this.makeRequest(_this.serverTokenEndpoint, data).then(function(response) {
292
334
  Ember.run(function() {
293
335
  expiresIn = response.expires_in || expiresIn;
294
336
  refreshToken = response.refresh_token || refreshToken;
@@ -0,0 +1,203 @@
1
+ (function(global) {
2
+
3
+ var define, requireModule;
4
+
5
+ (function() {
6
+ var registry = {}, seen = {};
7
+
8
+ define = function(name, deps, callback) {
9
+ registry[name] = { deps: deps, callback: callback };
10
+ };
11
+
12
+ requireModule = function(name) {
13
+ if (seen.hasOwnProperty(name)) { return seen[name]; }
14
+ seen[name] = {};
15
+
16
+ if (!registry[name]) {
17
+ throw new Error("Could not find module " + name);
18
+ }
19
+
20
+ var mod = registry[name],
21
+ deps = mod.deps,
22
+ callback = mod.callback,
23
+ reified = [],
24
+ exports;
25
+
26
+ for (var i=0, l=deps.length; i<l; i++) {
27
+ if (deps[i] === 'exports') {
28
+ reified.push(exports = {});
29
+ } else {
30
+ reified.push(requireModule(resolve(deps[i])));
31
+ }
32
+ }
33
+
34
+ var value = callback.apply(this, reified);
35
+ return seen[name] = exports || value;
36
+
37
+ function resolve(child) {
38
+ if (child.charAt(0) !== '.') { return child; }
39
+ var parts = child.split("/");
40
+ var parentBase = name.split("/").slice(0, -1);
41
+
42
+ for (var i=0, l=parts.length; i<l; i++) {
43
+ var part = parts[i];
44
+
45
+ if (part === '..') { parentBase.pop(); }
46
+ else if (part === '.') { continue; }
47
+ else { parentBase.push(part); }
48
+ }
49
+
50
+ return parentBase.join("/");
51
+ }
52
+ };
53
+
54
+ requireModule.registry = registry;
55
+ })();
56
+
57
+ define("simple-auth-torii/authenticators/torii",
58
+ ["simple-auth/authenticators/base","exports"],
59
+ function(__dependency1__, __exports__) {
60
+ "use strict";
61
+ var Base = __dependency1__["default"];
62
+
63
+ var global = (typeof window !== 'undefined') ? window : {},
64
+ Ember = global.Ember;
65
+
66
+ /**
67
+ Authenticator that wraps the
68
+ [Torii library](https://github.com/Vestorly/torii).
69
+
70
+ _The factory for this authenticator is registered as
71
+ `'simple-auth-authenticator:torii'` in Ember's container._
72
+
73
+ @class Torii
74
+ @namespace SimpleAuth.Authenticators
75
+ @module simple-auth-torii/authenticators/torii
76
+ @extends Base
77
+ */
78
+ __exports__["default"] = Base.extend({
79
+ /**
80
+ @property torii
81
+ @private
82
+ */
83
+ torii: null,
84
+
85
+ /**
86
+ @property provider
87
+ @private
88
+ */
89
+ provider: null,
90
+
91
+ /**
92
+ Restores the session by calling the torii provider's `fetch` method.
93
+
94
+ @method restore
95
+ @param {Object} data The data to restore the session from
96
+ @return {Ember.RSVP.Promise} A promise that when it resolves results in the session being authenticated
97
+ */
98
+ restore: function(data) {
99
+ var _this = this;
100
+ data = data || {};
101
+ return new Ember.RSVP.Promise(function(resolve, reject) {
102
+ if (!Ember.isEmpty(data.provider)) {
103
+ var provider = data.provider;
104
+ _this.torii.fetch(data.provider, data).then(function(data) {
105
+ _this.resolveWith(provider, data, resolve);
106
+ }, function() {
107
+ delete _this.provider;
108
+ reject();
109
+ });
110
+ } else {
111
+ delete _this.provider;
112
+ reject();
113
+ }
114
+ });
115
+ },
116
+
117
+ /**
118
+ Authenticates the session by opening the torii provider. For more
119
+ documentation on torii, see the
120
+ [project's README](https://github.com/Vestorly/torii#readme).
121
+
122
+ @method authenticate
123
+ @param {String} provider The provider to authenticate the session with
124
+ @return {Ember.RSVP.Promise} A promise that resolves when the provider successfully authenticates a user and rejects otherwise
125
+ */
126
+ authenticate: function(provider) {
127
+ var _this = this;
128
+ return new Ember.RSVP.Promise(function(resolve, reject) {
129
+ _this.torii.open(provider).then(function(data) {
130
+ _this.resolveWith(provider, data, resolve);
131
+ }, reject);
132
+ });
133
+ },
134
+
135
+ /**
136
+ Closes the torii provider.
137
+
138
+ @method invalidate
139
+ @param {Object} data The data that's stored in the session
140
+ @return {Ember.RSVP.Promise} A promise that resolves when the provider successfully closes and rejects otherwise
141
+ */
142
+ invalidate: function(data) {
143
+ var _this = this;
144
+ return new Ember.RSVP.Promise(function(resolve, reject) {
145
+ _this.torii.close(_this.provider).then(function() {
146
+ delete _this.provider;
147
+ resolve();
148
+ }, reject);
149
+ });
150
+ },
151
+
152
+ /**
153
+ @method resolveWith
154
+ @private
155
+ */
156
+ resolveWith: function(provider, data, resolve) {
157
+ data.provider = provider;
158
+ this.provider = data.provider;
159
+ resolve(data);
160
+ }
161
+
162
+ });
163
+ });
164
+ define("simple-auth-torii/ember",
165
+ ["./initializer"],
166
+ function(__dependency1__) {
167
+ "use strict";
168
+ var global = (typeof window !== 'undefined') ? window : {},
169
+ Ember = global.Ember;
170
+
171
+ var initializer = __dependency1__["default"];
172
+
173
+ Ember.onLoad('Ember.Application', function(Application) {
174
+ Application.initializer(initializer);
175
+ });
176
+ });
177
+ define("simple-auth-torii/initializer",
178
+ ["simple-auth-torii/authenticators/torii","exports"],
179
+ function(__dependency1__, __exports__) {
180
+ "use strict";
181
+ var Authenticator = __dependency1__["default"];
182
+
183
+ __exports__["default"] = {
184
+ name: 'simple-auth-torii',
185
+ before: 'simple-auth',
186
+ after: 'torii',
187
+ initialize: function(container, application) {
188
+ var torii = container.lookup('torii:main');
189
+ var authenticator = Authenticator.create({ torii: torii });
190
+ container.register('simple-auth-authenticator:torii', authenticator, { instantiate: false });
191
+ }
192
+ };
193
+ });
194
+ define('simple-auth/authenticators/base', ['exports'], function(__exports__) {
195
+ __exports__['default'] = global.SimpleAuth.Authenticators.Base;
196
+ });
197
+
198
+ var Authenticator = requireModule('simple-auth-torii/authenticators/torii').default;
199
+
200
+ global.SimpleAuth.Authenticators.Torii = Authenticator;
201
+
202
+ requireModule('simple-auth-torii/ember');
203
+ })((typeof global !== 'undefined') ? global : window);
@@ -482,6 +482,7 @@ define("simple-auth/mixins/application-route-mixin",
482
482
  @private
483
483
  */
484
484
  beforeModel: function(transition) {
485
+ this._super(transition);
485
486
  var _this = this;
486
487
  Ember.A([
487
488
  'sessionAuthenticationSucceeded',
@@ -675,6 +676,7 @@ define("simple-auth/mixins/authenticated-route-mixin",
675
676
  @param {Transition} transition The transition that lead to this route
676
677
  */
677
678
  beforeModel: function(transition) {
679
+ this._super(transition);
678
680
  if (!this.get(Configuration.sessionPropertyName).get('isAuthenticated')) {
679
681
  transition.abort();
680
682
  this.get(Configuration.sessionPropertyName).set('attemptedTransition', transition);
@@ -1542,7 +1544,6 @@ define("simple-auth/utils/is-secure-url",
1542
1544
  }
1543
1545
  });
1544
1546
  var initializer = requireModule('simple-auth/initializer').default;
1545
- var setup = requireModule('simple-auth/setup').default;
1546
1547
  var Configuration = requireModule('simple-auth/configuration').default;
1547
1548
  var Session = requireModule('simple-auth/session').default;
1548
1549
  var BaseAuthenticator = requireModule('simple-auth/authenticators/base').default;
@@ -1559,8 +1560,6 @@ var AuthenticationControllerMixin = requireModule('simple-auth/mixins/authentica
1559
1560
  var LoginControllerMixin = requireModule('simple-auth/mixins/login-controller-mixin').default;
1560
1561
 
1561
1562
  global.SimpleAuth = {
1562
- setup: setup,
1563
-
1564
1563
  Configuration: Configuration,
1565
1564
 
1566
1565
  Session: Session,
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.2
4
+ version: 0.6.3
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-06-26 00:00:00.000000000 Z
11
+ date: 2014-07-10 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-torii.js
69
70
  - vendor/assets/javascripts/ember-simple-auth.js
70
71
  homepage: https://github.com/doodzik/ember_simple_auth-rails
71
72
  licenses: