Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
closes TryGhost#5951
- update to esa 1.0
  • Loading branch information
acburdine committed Oct 18, 2015
1 parent 0a1e17a commit 87e54c0
Show file tree
Hide file tree
Showing 30 changed files with 151 additions and 159 deletions.
12 changes: 11 additions & 1 deletion core/client/app/authenticators/oauth2.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import Ember from 'ember';
import Authenticator from 'simple-auth-oauth2/authenticators/oauth2';
import Authenticator from 'ember-simple-auth/authenticators/oauth2-password-grant';

export default Authenticator.extend({
config: Ember.inject.service(),
ghostPaths: Ember.inject.service('ghost-paths'),

serverTokenEndpoint: Ember.computed('ghostPaths.apiRoot', function () {
return this.get('ghostPaths.apiRoot') + '/authentication/token';
}),

serverTokenRevocationEndpoint: Ember.computed('ghostPaths.apiRoot', function () {
return this.get('ghostPaths.apiRoot') + '/authentication/revoke';
}),

makeRequest: function (url, data) {
data.client_id = this.get('config.clientId');
data.client_secret = this.get('config.clientSecret');
Expand Down
3 changes: 3 additions & 0 deletions core/client/app/authorizers/oauth2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Oauth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer';

export default Oauth2Bearer;
1 change: 1 addition & 0 deletions core/client/app/components/gh-nav-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default Ember.Component.extend({
classNameBindings: ['open'],

config: Ember.inject.service(),
session: Ember.inject.service(),

open: false,

Expand Down
6 changes: 3 additions & 3 deletions core/client/app/controllers/modals/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default Ember.Controller.extend(ValidationEngine, {

application: Ember.inject.controller(),
notifications: Ember.inject.service(),
session: Ember.inject.service(),

identification: Ember.computed('session.user.email', function () {
return this.get('session.user.email');
Expand All @@ -15,13 +16,12 @@ export default Ember.Controller.extend(ValidationEngine, {
actions: {
authenticate: function () {
var appController = this.get('application'),
authStrategy = 'ghost-authenticator:oauth2-password-grant',
data = this.getProperties('identification', 'password'),
authStrategy = 'authenticator:oauth2',
self = this;

appController.set('skipAuthSuccessHandler', true);

this.get('session').authenticate(authStrategy, data).then(function () {
this.get('session').authenticate(authStrategy, this.get('identification'), this.get('password')).then(function () {
self.send('closeModal');
self.set('password', '');
}).catch(function () {
Expand Down
1 change: 1 addition & 0 deletions core/client/app/controllers/post-settings-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default Ember.Controller.extend(SettingsMenuMixin, {
config: Ember.inject.service(),
ghostPaths: Ember.inject.service('ghost-paths'),
notifications: Ember.inject.service(),
session: Ember.inject.service(),

initializeSelectedAuthor: Ember.observer('model', function () {
var self = this;
Expand Down
6 changes: 2 additions & 4 deletions core/client/app/controllers/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default Ember.Controller.extend(ValidationEngine, {

ghostPaths: Ember.inject.service('ghost-paths'),
notifications: Ember.inject.service(),
session: Ember.inject.service(),

email: Ember.computed('token', function () {
// The token base64 encodes the email (and some other stuff),
Expand Down Expand Up @@ -46,10 +47,7 @@ export default Ember.Controller.extend(ValidationEngine, {
}).then(function (resp) {
self.toggleProperty('submitting');
self.get('notifications').showAlert(resp.passwordreset[0].message, {type: 'warn', delayed: true, key: 'password.reset'});
self.get('session').authenticate('ghost-authenticator:oauth2-password-grant', {
identification: self.get('email'),
password: credentials.newPassword
});
self.get('session').authenticate('authenticator:oauth2', self.get('email'), credentials.newPassword);
}).catch(function (response) {
self.get('notifications').showAPIError(response, {key: 'password.reset'});
self.toggleProperty('submitting');
Expand Down
1 change: 1 addition & 0 deletions core/client/app/controllers/settings/labs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default Ember.Controller.extend({

ghostPaths: Ember.inject.service('ghost-paths'),
notifications: Ember.inject.service(),
session: Ember.inject.service(),

labsJSON: Ember.computed('model.labs', function () {
return JSON.parse(this.get('model.labs') || {});
Expand Down
6 changes: 2 additions & 4 deletions core/client/app/controllers/setup/two.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default Ember.Controller.extend(ValidationEngine, {
notifications: Ember.inject.service(),
application: Ember.inject.controller(),
config: Ember.inject.service(),
session: Ember.inject.service(),

// ValidationEngine settings
validationType: 'setup',
Expand Down Expand Up @@ -87,10 +88,7 @@ export default Ember.Controller.extend(ValidationEngine, {
config.set('blogTitle', data.blogTitle);
// Don't call the success handler, otherwise we will be redirected to admin
self.get('application').set('skipAuthSuccessHandler', true);
self.get('session').authenticate('ghost-authenticator:oauth2-password-grant', {
identification: self.get('email'),
password: self.get('password')
}).then(function () {
self.get('session').authenticate('authenticator:oauth2', self.get('email'), self.get('password')).then(function () {
self.set('blogCreated', true);
if (data.image) {
self.sendImage(result.users[0])
Expand Down
27 changes: 15 additions & 12 deletions core/client/app/controllers/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default Ember.Controller.extend(ValidationEngine, {

ghostPaths: Ember.inject.service('ghost-paths'),
notifications: Ember.inject.service(),
session: Ember.inject.service(),
application: Ember.inject.controller(),
flowErrors: '',

// ValidationEngine settings
Expand All @@ -18,29 +20,30 @@ export default Ember.Controller.extend(ValidationEngine, {
authenticate: function () {
var self = this,
model = this.get('model'),
authStrategy = 'ghost-authenticator:oauth2-password-grant',
data = model.getProperties(this.authProperties);
authStrategy = 'authenticator:oauth2';

// Authentication transitions to posts.index, we can leave spinner running unless there is an error
this.get('session').authenticate(authStrategy, data).catch(function (err) {
this.get('session').authenticate(authStrategy, model.get('identification'), model.get('password')).catch(function (error) {
self.toggleProperty('loggingIn');

if (err.errors) {
self.set('flowErrors', err.errors[0].message.string);
if (error.errors) {
error.errors.forEach(function (err) {
err.message = err.message.htmlSafe();
});

// this catches both 'no user' and 'user inactive' errors
// long term, we probably need to introduce error codes from the server
if (err.errors[0].message.string.match(/user with that email/)) {
self.set('flowErrors', error.errors[0].message.string);

if (error.errors[0].message.string.match(/user with that email/)) {
self.get('model.errors').add('identification', '');
}

if (err.errors[0].message.string.match(/password is incorrect/)) {
if (error.errors[0].message.string.match(/password is incorrect/)) {
self.get('model.errors').add('password', '');
}
} else {
// Connection errors don't return proper status message, only req.body
self.get('notifications').showAlert('There was a problem on the server.', {type: 'error', key: 'session.authenticate.failed'});
}
// if authentication fails a rejected promise will be returned.
// it needs to be caught so it doesn't generate an exception in the console,
// but it's actually "handled" by the sessionAuthenticationFailed action handler.
});
},

Expand Down
6 changes: 2 additions & 4 deletions core/client/app/controllers/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default Ember.Controller.extend(ValidationEngine, {
ghostPaths: Ember.inject.service('ghost-paths'),
config: Ember.inject.service(),
notifications: Ember.inject.service(),
session: Ember.inject.service(),

sendImage: function () {
var self = this,
Expand Down Expand Up @@ -66,10 +67,7 @@ export default Ember.Controller.extend(ValidationEngine, {
}]
}
}).then(function () {
self.get('session').authenticate('ghost-authenticator:oauth2-password-grant', {
identification: self.get('model.email'),
password: self.get('model.password')
}).then(function () {
self.get('session').authenticate('authenticator:oauth2', self.get('model.email'), self.get('model.password')).then(function () {
if (image) {
self.sendImage();
}
Expand Down
2 changes: 2 additions & 0 deletions core/client/app/controllers/team/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Ember from 'ember';

export default Ember.Controller.extend({

session: Ember.inject.service(),

users: Ember.computed.alias('model'),

activeUsers: Ember.computed.filter('users', function (user) {
Expand Down
1 change: 1 addition & 0 deletions core/client/app/controllers/team/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default Ember.Controller.extend(ValidationEngine, {

ghostPaths: Ember.inject.service('ghost-paths'),
notifications: Ember.inject.service(),
session: Ember.inject.service(),

currentUser: Ember.computed.alias('session.user'),

Expand Down
17 changes: 17 additions & 0 deletions core/client/app/initializers/ember-simple-auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ENV from '../config/environment';
import ghostPaths from '../utils/ghost-paths';
import Configuration from 'ember-simple-auth/configuration';
import setupSession from 'ember-simple-auth/initializers/setup-session';
import setupSessionService from 'ember-simple-auth/initializers/setup-session-service';

export default {
name: 'ember-simple-auth',
initialize: function (registry) {
const config = ENV['ember-simple-auth'] || {};
config.baseURL = ghostPaths().adminRoot;
Configuration.load(config);

setupSession(registry);
setupSessionService(registry);
}
};
12 changes: 0 additions & 12 deletions core/client/app/initializers/ghost-authenticator.js

This file was deleted.

16 changes: 0 additions & 16 deletions core/client/app/initializers/simple-auth-env.js

This file was deleted.

18 changes: 0 additions & 18 deletions core/client/app/instance-initializers/authentication.js

This file was deleted.

19 changes: 19 additions & 0 deletions core/client/app/instance-initializers/oauth-prefilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Ember from 'ember';

export default {
name: 'oauth-prefilter',
after: 'ember-simple-auth',

initialize: function (application) {
var session = application.container.lookup('service:session');

Ember.$.ajaxPrefilter(function (options) {
session.authorize('authorizer:oauth2', function (headerName, headerValue) {
var headerObject = {};

headerObject[headerName] = headerValue;
options.headers = Ember.merge(options.headers || {}, headerObject);
});
});
}
};
Loading

0 comments on commit 87e54c0

Please sign in to comment.