ember-cli-simple-auth
Advanced tools
Comparing version 0.6.2 to 0.6.3
{ | ||
"name": "ember-cli-simple-auth", | ||
"dependencies": { | ||
"ember-simple-auth": "0.6.2" | ||
"ember-simple-auth": "0.6.3" | ||
} | ||
} |
25
index.js
@@ -28,13 +28,16 @@ var path = require('path'); | ||
this.app.import('vendor/ember-simple-auth/simple-auth.amd.js', { | ||
'simple-auth/authenticators/base': ['default'], | ||
'simple-auth/authorizers/base': ['default'], | ||
'simple-auth/mixins/application-route-mixin': ['default'], | ||
'simple-auth/mixins/authenticated-route-mixin': ['default'], | ||
'simple-auth/mixins/authentication-controller-mixin': ['default'], | ||
'simple-auth/mixins/login-controller-mixin': ['default'], | ||
'simple-auth/stores/base': ['default'], | ||
'simple-auth/stores/ephemeral': ['default'], | ||
'simple-auth/stores/local-storage': ['default'], | ||
'simple-auth/configuration': ['default'], | ||
'simple-auth/initializer': ['default'] | ||
exports: { | ||
'simple-auth/authenticators/base': ['default'], | ||
'simple-auth/authorizers/base': ['default'], | ||
'simple-auth/mixins/application-route-mixin': ['default'], | ||
'simple-auth/mixins/authenticated-route-mixin': ['default'], | ||
'simple-auth/mixins/authentication-controller-mixin': ['default'], | ||
'simple-auth/mixins/login-controller-mixin': ['default'], | ||
'simple-auth/stores/base': ['default'], | ||
'simple-auth/stores/ephemeral': ['default'], | ||
'simple-auth/stores/local-storage': ['default'], | ||
'simple-auth/session': ['default'], | ||
'simple-auth/configuration': ['default'], | ||
'simple-auth/initializer': ['default'] | ||
} | ||
}); | ||
@@ -41,0 +44,0 @@ }; |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"description": "Include the Ember Simple Auth base library into an Ember CLI application.", | ||
@@ -8,0 +8,0 @@ "main": "index.js", |
{ | ||
"name": "ember-simple-auth", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"main": [ | ||
@@ -18,11 +18,11 @@ "./simple-auth.js", | ||
"homepage": "https://github.com/simplabs/ember-simple-auth-component", | ||
"_release": "0.6.2", | ||
"_release": "0.6.3", | ||
"_resolution": { | ||
"type": "version", | ||
"tag": "0.6.2", | ||
"commit": "6463b0d7b42f975478c294408ffc0c610b3d3db0" | ||
"tag": "0.6.3", | ||
"commit": "c2267d221265706f788d1aaefaebdf2808e93ea2" | ||
}, | ||
"_source": "git://github.com/simplabs/ember-simple-auth-component.git", | ||
"_target": "0.6.2", | ||
"_target": "0.6.3", | ||
"_originalSource": "ember-simple-auth" | ||
} |
{ | ||
"name": "ember-simple-auth", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "./simple-auth.js", |
@@ -58,2 +58,21 @@ define("simple-auth-oauth2/authenticators/oauth2", | ||
/** | ||
The endpoint on the server the authenticator uses to revoke tokens. Only | ||
set this if the server actually supports token revokation. | ||
This value can be configured via the global environment object: | ||
```js | ||
window.ENV = window.ENV || {}; | ||
window.ENV['simple-auth-oauth2'] = { | ||
serverTokenRevokationEndpoint: '/some/custom/endpoint' | ||
} | ||
``` | ||
@property serverTokenRevokationEndpoint | ||
@type String | ||
@default null | ||
*/ | ||
serverTokenRevokationEndpoint: null, | ||
/** | ||
Sets whether the authenticator automatically refreshes access tokens. | ||
@@ -87,5 +106,6 @@ | ||
init: function() { | ||
var globalConfig = getGlobalConfig('simple-auth-oauth2'); | ||
this.serverTokenEndpoint = globalConfig.serverTokenEndpoint || this.serverTokenEndpoint; | ||
this.refreshAccessTokens = globalConfig.refreshAccessTokens || this.refreshAccessTokens; | ||
var globalConfig = getGlobalConfig('simple-auth-oauth2'); | ||
this.serverTokenEndpoint = globalConfig.serverTokenEndpoint || this.serverTokenEndpoint; | ||
this.serverTokenRevokationEndpoint = globalConfig.serverTokenRevokationEndpoint || this.serverTokenRevokationEndpoint; | ||
this.refreshAccessTokens = globalConfig.refreshAccessTokens || this.refreshAccessTokens; | ||
}, | ||
@@ -153,3 +173,3 @@ | ||
var data = { grant_type: 'password', username: credentials.identification, password: credentials.password }; | ||
_this.makeRequest(data).then(function(response) { | ||
_this.makeRequest(_this.serverTokenEndpoint, data).then(function(response) { | ||
Ember.run(function() { | ||
@@ -173,13 +193,34 @@ var expiresAt = _this.absolutizeExpirationTime(response.expires_in); | ||
@method invalidate | ||
@param {Object} data The data of the session to be invalidated | ||
@return {Ember.RSVP.Promise} A resolving promise | ||
*/ | ||
invalidate: function() { | ||
Ember.run.cancel(this._refreshTokenTimeout); | ||
delete this._refreshTokenTimeout; | ||
return new Ember.RSVP.resolve(); | ||
invalidate: function(data) { | ||
var _this = this; | ||
function success(resolve) { | ||
Ember.run.cancel(_this._refreshTokenTimeout); | ||
delete _this._refreshTokenTimeout; | ||
resolve(); | ||
} | ||
return new Ember.RSVP.Promise(function(resolve, reject) { | ||
if (!Ember.isEmpty(_this.serverTokenRevokationEndpoint)) { | ||
var requests = []; | ||
Ember.A(['access_token', 'refresh_token']).forEach(function(tokenType) { | ||
if (!Ember.isEmpty(data[tokenType])) { | ||
requests.push(_this.makeRequest(_this.serverTokenRevokationEndpoint, { | ||
token_type_hint: tokenType, token: data[tokenType] | ||
})); | ||
} | ||
}); | ||
Ember.$.when.apply(Ember.$, requests).always(function(responses) { | ||
success(resolve); | ||
}); | ||
} else { | ||
success(resolve); | ||
} | ||
}); | ||
}, | ||
/** | ||
Sends an `AJAX` request to the `serverTokenEndpoint`. This will always be a | ||
_"POST"_ request with content type _"application/x-www-form-urlencoded"_ as | ||
Sends an `AJAX` request to the `url`. This will always be a _"POST"_ | ||
request with content type _"application/x-www-form-urlencoded"_ as | ||
specified in [RFC 6749](http://tools.ietf.org/html/rfc6749). | ||
@@ -192,2 +233,3 @@ | ||
@method makeRequest | ||
@param {Object} url The url to send the request to | ||
@param {Object} data The data to send with the request, e.g. username and password or the refresh token | ||
@@ -197,8 +239,8 @@ @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 | ||
*/ | ||
makeRequest: function(data) { | ||
if (!isSecureUrl(this.serverTokenEndpoint)) { | ||
makeRequest: function(url, data) { | ||
if (!isSecureUrl(url)) { | ||
Ember.Logger.warn('Credentials are transmitted via an insecure connection - use HTTPS to keep them secure.'); | ||
} | ||
return Ember.$.ajax({ | ||
url: this.serverTokenEndpoint, | ||
url: url, | ||
type: 'POST', | ||
@@ -241,3 +283,3 @@ data: data, | ||
return new Ember.RSVP.Promise(function(resolve, reject) { | ||
_this.makeRequest(data).then(function(response) { | ||
_this.makeRequest(_this.serverTokenEndpoint, data).then(function(response) { | ||
Ember.run(function() { | ||
@@ -244,0 +286,0 @@ expiresIn = response.expires_in || expiresIn; |
@@ -114,2 +114,21 @@ (function(global) { | ||
/** | ||
The endpoint on the server the authenticator uses to revoke tokens. Only | ||
set this if the server actually supports token revokation. | ||
This value can be configured via the global environment object: | ||
```js | ||
window.ENV = window.ENV || {}; | ||
window.ENV['simple-auth-oauth2'] = { | ||
serverTokenRevokationEndpoint: '/some/custom/endpoint' | ||
} | ||
``` | ||
@property serverTokenRevokationEndpoint | ||
@type String | ||
@default null | ||
*/ | ||
serverTokenRevokationEndpoint: null, | ||
/** | ||
Sets whether the authenticator automatically refreshes access tokens. | ||
@@ -143,5 +162,6 @@ | ||
init: function() { | ||
var globalConfig = getGlobalConfig('simple-auth-oauth2'); | ||
this.serverTokenEndpoint = globalConfig.serverTokenEndpoint || this.serverTokenEndpoint; | ||
this.refreshAccessTokens = globalConfig.refreshAccessTokens || this.refreshAccessTokens; | ||
var globalConfig = getGlobalConfig('simple-auth-oauth2'); | ||
this.serverTokenEndpoint = globalConfig.serverTokenEndpoint || this.serverTokenEndpoint; | ||
this.serverTokenRevokationEndpoint = globalConfig.serverTokenRevokationEndpoint || this.serverTokenRevokationEndpoint; | ||
this.refreshAccessTokens = globalConfig.refreshAccessTokens || this.refreshAccessTokens; | ||
}, | ||
@@ -209,3 +229,3 @@ | ||
var data = { grant_type: 'password', username: credentials.identification, password: credentials.password }; | ||
_this.makeRequest(data).then(function(response) { | ||
_this.makeRequest(_this.serverTokenEndpoint, data).then(function(response) { | ||
Ember.run(function() { | ||
@@ -229,13 +249,34 @@ var expiresAt = _this.absolutizeExpirationTime(response.expires_in); | ||
@method invalidate | ||
@param {Object} data The data of the session to be invalidated | ||
@return {Ember.RSVP.Promise} A resolving promise | ||
*/ | ||
invalidate: function() { | ||
Ember.run.cancel(this._refreshTokenTimeout); | ||
delete this._refreshTokenTimeout; | ||
return new Ember.RSVP.resolve(); | ||
invalidate: function(data) { | ||
var _this = this; | ||
function success(resolve) { | ||
Ember.run.cancel(_this._refreshTokenTimeout); | ||
delete _this._refreshTokenTimeout; | ||
resolve(); | ||
} | ||
return new Ember.RSVP.Promise(function(resolve, reject) { | ||
if (!Ember.isEmpty(_this.serverTokenRevokationEndpoint)) { | ||
var requests = []; | ||
Ember.A(['access_token', 'refresh_token']).forEach(function(tokenType) { | ||
if (!Ember.isEmpty(data[tokenType])) { | ||
requests.push(_this.makeRequest(_this.serverTokenRevokationEndpoint, { | ||
token_type_hint: tokenType, token: data[tokenType] | ||
})); | ||
} | ||
}); | ||
Ember.$.when.apply(Ember.$, requests).always(function(responses) { | ||
success(resolve); | ||
}); | ||
} else { | ||
success(resolve); | ||
} | ||
}); | ||
}, | ||
/** | ||
Sends an `AJAX` request to the `serverTokenEndpoint`. This will always be a | ||
_"POST"_ request with content type _"application/x-www-form-urlencoded"_ as | ||
Sends an `AJAX` request to the `url`. This will always be a _"POST"_ | ||
request with content type _"application/x-www-form-urlencoded"_ as | ||
specified in [RFC 6749](http://tools.ietf.org/html/rfc6749). | ||
@@ -248,2 +289,3 @@ | ||
@method makeRequest | ||
@param {Object} url The url to send the request to | ||
@param {Object} data The data to send with the request, e.g. username and password or the refresh token | ||
@@ -253,8 +295,8 @@ @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 | ||
*/ | ||
makeRequest: function(data) { | ||
if (!isSecureUrl(this.serverTokenEndpoint)) { | ||
makeRequest: function(url, data) { | ||
if (!isSecureUrl(url)) { | ||
Ember.Logger.warn('Credentials are transmitted via an insecure connection - use HTTPS to keep them secure.'); | ||
} | ||
return Ember.$.ajax({ | ||
url: this.serverTokenEndpoint, | ||
url: url, | ||
type: 'POST', | ||
@@ -297,3 +339,3 @@ data: data, | ||
return new Ember.RSVP.Promise(function(resolve, reject) { | ||
_this.makeRequest(data).then(function(response) { | ||
_this.makeRequest(_this.serverTokenEndpoint, data).then(function(response) { | ||
Ember.run(function() { | ||
@@ -300,0 +342,0 @@ expiresIn = response.expires_in || expiresIn; |
@@ -429,2 +429,3 @@ define("simple-auth/authenticators/base", | ||
beforeModel: function(transition) { | ||
this._super(transition); | ||
var _this = this; | ||
@@ -623,2 +624,3 @@ Ember.A([ | ||
beforeModel: function(transition) { | ||
this._super(transition); | ||
if (!this.get(Configuration.sessionPropertyName).get('isAuthenticated')) { | ||
@@ -625,0 +627,0 @@ transition.abort(); |
@@ -485,2 +485,3 @@ (function(global) { | ||
beforeModel: function(transition) { | ||
this._super(transition); | ||
var _this = this; | ||
@@ -679,2 +680,3 @@ Ember.A([ | ||
beforeModel: function(transition) { | ||
this._super(transition); | ||
if (!this.get(Configuration.sessionPropertyName).get('isAuthenticated')) { | ||
@@ -1547,3 +1549,2 @@ transition.abort(); | ||
var initializer = requireModule('simple-auth/initializer').default; | ||
var setup = requireModule('simple-auth/setup').default; | ||
var Configuration = requireModule('simple-auth/configuration').default; | ||
@@ -1565,4 +1566,2 @@ var Session = requireModule('simple-auth/session').default; | ||
global.SimpleAuth = { | ||
setup: setup, | ||
Configuration: Configuration, | ||
@@ -1569,0 +1568,0 @@ |
4058592
140
97607