Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoow committed Jul 25, 2014
2 parents a67d9ef + d4bc9c9 commit 6190da9
Show file tree
Hide file tree
Showing 81 changed files with 767 additions and 461 deletions.
88 changes: 88 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,91 @@
# 0.6.4

* __The new package `ember-simple-auth-testing` was added that contains test
helpers__ that simplify testing of authenticated routes, e.g.:

```js
test('a protected route is accessible when the session is authenticated', function() {
expect(1);
authenticateSession(); // <--
visit('/protected');

andThen(function() {
equal(currentRouteName(), 'protected');
});
});
```

* __Ember Simple Auth now allows to define a custom session class__ which e.g.
makes adding custom methods to the session much simpler, e.g.:

```js
App.CustomSession = SimpleAuth.Session.extend({
account: function() {
var accountId = this.get('account_id');
if (!Ember.isEmpty(accountId)) {
return this.container.lookup('store:main').find('account', accountId);
}
}.property('account_id')
});
container.register('session:custom', App.CustomSession);
window.ENV['simple-auth'] = {
session: 'session:custom',
}
```

* __A race condition was fixed that could have broken synchronization of
multiple tabs or windows__, see #254. The stores will now only store one
cookie, one `localStorage` key etc. holding a JSON representation of the
session's data instead of one cookie, `localStorage` key etc. per property.
__This change includes 2 breaking changes:__
* The cookie store's `cookieNamePrefix` property is now just `cookieName`
as there's only one cookie now.
* The `localStorage` store's `keyPrefix` property is now just `key` as
there's only one key now.
* The session will now persist custom content that is assigned manually without
the authenticator, see #260.
* A bug was fixed that caused session events to trigger multiple action
invocations when the application was started via a deep link to an
authenticated route, see #257.
* The AMD distribution does no longer require the `Ember` global but will try
to require it with `require('ember')` if the global does not exist, see #255.
* The used Ember Simple Auth libraries and their respective will now be logged
on application startup together with the Ember core libraries, e.g.:
```
[Debug] DEBUG: -------------------------------
[Debug] DEBUG: Ember : 1.6.1
[Debug] DEBUG: Handlebars : 1.0.0
[Debug] DEBUG: jQuery : 1.9.1
[Debug] DEBUG: Ember Simple Auth : 0.6.4
[Debug] DEBUG: Ember Simple Auth OAuth 2.0 : 0.6.4
[Debug] DEBUG: -------------------------------
```
* The `LoginControllerMixin`'s `authenticate` action now returns the promise
returned by the session so that controllers can use that to handle successful
authentication or authentication errors, e.g.:

```js
App.LoginController = Ember.Controller.extend(SimpleAuth.LoginControllerMixin, {
authenticator: 'simple-auth-authenticator:oauth2-password-grant',
actions: {
authenticate: function() {
this._super().then(function() {
// authentication succeeded
},
function(error) {
// authentication failed
});
}
}
});
```

* Fixed a bug where the OAuth 1.0 authenticator would not try to refresh the
token on restore in some situations, see #249.

# 0.6.3

* added new extension library
Expand Down
26 changes: 22 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = function(grunt) {
'clean',
'transpile:amd',
'concat:amd',
'concat:browser'
'concat:browser',
'string-replace:version'
]);

this.registerTask('build_tests', "Builds Ember Simple Auth's tests", [
Expand Down Expand Up @@ -124,7 +125,7 @@ module.exports = function(grunt) {
files: (function() {
var files = {};
packages.forEach(function(pkg) {
files['tmp/' + pkg.name + '.amd.js'] = ['tmp/libs/' + pkg.main + '.js', 'tmp/libs/' + pkg.main + '/**/*.js'];
files['tmp/' + pkg.name + '.amd.js'] = ['packages/' + pkg.name + '/wrap/amd.start', 'packages/' + pkg.name + '/wrap/register-library', 'tmp/libs/' + pkg.main + '.js', 'tmp/libs/' + pkg.main + '/**/*.js', 'packages/' + pkg.name + '/wrap/amd.end'];
});
return files;
})()
Expand All @@ -133,7 +134,7 @@ module.exports = function(grunt) {
files: (function() {
var files = {};
packages.forEach(function(pkg) {
files['tmp/' + pkg.name + '.js'] = ['packages/' + pkg.name + '/wrap/browser.start', 'vendor/loader.js', 'tmp/libs/' + pkg.main + '.js', 'tmp/libs/' + pkg.main + '/**/*.js', 'packages/' + pkg.name + '/wrap/browser.end'];
files['tmp/' + pkg.name + '.js'] = ['packages/' + pkg.name + '/wrap/browser.start', 'packages/' + pkg.name + '/wrap/register-library', 'vendor/loader.js', 'tmp/libs/' + pkg.main + '.js', 'tmp/libs/' + pkg.main + '/**/*.js', 'packages/' + pkg.name + '/wrap/browser.end'];
});
return files;
})()
Expand All @@ -142,13 +143,29 @@ module.exports = function(grunt) {
files: (function() {
var files = {};
packages.forEach(function(pkg) {
files['tmp/' + pkg.name + '-tests.amd.js'] = ['tmp/tests/' + pkg.name + '/**/*.js'];
files['tmp/' + pkg.name + '-tests.amd.js'] = ['packages/' + pkg.name + '/wrap/amd.start', 'packages/' + pkg.name + '/wrap/register-library', 'tmp/tests/' + pkg.name + '/**/*.js', 'packages/' + pkg.name + '/wrap/amd.end'];
});
return files;
})()
}
},

'string-replace': {
version: {
files: {
'tmp/': 'tmp/*.js'
},
options: {
replacements: packages.map(function(pkg) {
return {
pattern: '{{ VERSION }}',
replacement: pkg.version
};
})
}
}
},

copy: {
plain_download: {
files: packages.map(function(pkg) {
Expand Down Expand Up @@ -281,4 +298,5 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.loadNpmTasks('grunt-compile-handlebars');
grunt.loadNpmTasks('grunt-lintspaces');
grunt.loadNpmTasks('grunt-string-replace');
};
17 changes: 10 additions & 7 deletions examples/2-errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,21 @@ <h1>Erroneous Page</h1>
// clear a potentially stale error message from previous login attempts
setupController: function(controller, model) {
controller.set('errorMessage', null);
},
}
});
App.LoginController = Ember.Controller.extend(SimpleAuth.LoginControllerMixin, {
authenticator: 'simple-auth-authenticator:oauth2-password-grant',
actions: {
// display an error when authentication fails
sessionAuthenticationFailed: function(error) {
var message = JSON.parse(error).error;
this.controller.set('errorMessage', message);
authenticate: function() {
var _this = this;
this._super().then(null, function(error) {
var message = JSON.parse(error).error;
_this.set('errorMessage', message);
});
}
}
});
App.LoginController = Ember.Controller.extend(SimpleAuth.LoginControllerMixin, {
authenticator: 'simple-auth-authenticator:oauth2-password-grant'
});

// make these routes protected
App.ProtectedRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin);
Expand Down
2 changes: 1 addition & 1 deletion examples/3-token-refresh.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1>Example with token refresh</h1>
</div>
{{#if session.isAuthenticated}}
<div class="alert alert-info">
The token is automatically refreshed every 10 seconds, it currently is: <code>{{ session.access_token }}</code>.
The token is automatically refreshed every 5 to 10 seconds, it currently is: <code>{{ session.access_token }}</code>.
</div>
{{else}}
<div class="alert alert-info">
Expand Down
26 changes: 15 additions & 11 deletions examples/4-authenticated-account.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,15 @@ <h1>Protected Page</h1>
// configure an authorizer to be used
window.ENV = window.ENV || {};
window.ENV['simple-auth'] = {
session: 'session:custom',
authorizer: 'simple-auth-authorizer:oauth2-bearer'
};
Ember.Application.initializer({
name: 'authentication',
before: 'simple-auth',
name: 'authentication',
before: 'simple-auth',
initialize: function(container, application) {
// customize the session so that it allows access to the account object
SimpleAuth.Session.reopen({
account: function() {
var accountId = this.get('account_id');
if (!Ember.isEmpty(accountId)) {
return container.lookup('store:main').find('account', accountId);
}
}.property('account_id')
});
// register the custom session so Ember Simple Auth can find it
container.register('session:custom', App.CustomSession);
// register the custom authenticator so the session can find it
container.register('authenticator:custom', App.CustomAuthenticator);
}
Expand All @@ -134,6 +128,16 @@ <h1>Protected Page</h1>
this.route('protected');
});

// the custom session that handles an authenticated account
App.CustomSession = SimpleAuth.Session.extend({
account: function() {
var accountId = this.get('account_id');
if (!Ember.isEmpty(accountId)) {
return this.container.lookup('store:main').find('account', accountId);
}
}.property('account_id')
});

// the custom authenticator that handles the authenticated account
App.CustomAuthenticator = SimpleAuth.Authenticators.OAuth2.extend({
authenticate: function(credentials) {
Expand Down
15 changes: 9 additions & 6 deletions examples/6-custom-server.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,20 @@ <h1>Protected Page</h1>
// clear a potentially stale error message from previous login attempts
setupController: function(controller, model) {
controller.set('errorMessage', null);
},
}
});
App.LoginController = Ember.Controller.extend(SimpleAuth.LoginControllerMixin, {
authenticator: 'authenticator:custom',
actions: {
// display an error when authentication fails
sessionAuthenticationFailed: function(message) {
this.controller.set('errorMessage', message);
authenticate: function() {
var _this = this;
this._super().then(null, function(message) {
_this.set('errorMessage', message);
});
}
}
});
App.LoginController = Ember.Controller.extend(SimpleAuth.LoginControllerMixin, {
authenticator: 'authenticator:custom'
});

// make these route protected
App.ProtectedRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"grunt-contrib-copy": "^0.5.0",
"grunt-contrib-concat": "^0.3.0",
"grunt-contrib-yuidoc": "^0.5.1",
"grunt-string-replace": "^0.2.7",
"yuidocjs": "^0.3.49",
"grunt-compile-handlebars": "^0.6.3",
"grunt-lintspaces": "^0.4.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
var global = (typeof window !== 'undefined') ? window : {},
Ember = global.Ember;

import initializer from './initializer';

Ember.onLoad('Ember.Application', function(Application) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
var global = (typeof window !== 'undefined') ? window : {},
Ember = global.Ember;

import Store from 'simple-auth-cookie-store/stores/cookie';

export default {
Expand Down
Loading

0 comments on commit 6190da9

Please sign in to comment.