mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Update to simple-auth 0.8
No issue - ember-simple-auth@0.8.0-beta.2. - Switch from SimpleAuth global to ember-cli-simple-auth and ES6 imports. - Refactor controllers to handle changes in 0.8. - Introduces a new initializer to override some configuration items that are set in environment.js but need to be set with information that's only (easily) available at runtime.
This commit is contained in:
parent
27569b097c
commit
e9326f6f6e
17 changed files with 73 additions and 47 deletions
|
@ -7,7 +7,6 @@
|
||||||
"$",
|
"$",
|
||||||
"validator",
|
"validator",
|
||||||
"ic",
|
"ic",
|
||||||
"SimpleAuth",
|
|
||||||
"NProgress",
|
"NProgress",
|
||||||
"moment"
|
"moment"
|
||||||
],
|
],
|
||||||
|
|
|
@ -52,8 +52,6 @@ app.import('bower_components/jquery-ui/ui/jquery-ui.js');
|
||||||
app.import('bower_components/jquery-file-upload/js/jquery.fileupload.js');
|
app.import('bower_components/jquery-file-upload/js/jquery.fileupload.js');
|
||||||
app.import('bower_components/fastclick/lib/fastclick.js');
|
app.import('bower_components/fastclick/lib/fastclick.js');
|
||||||
app.import('bower_components/nprogress/nprogress.js');
|
app.import('bower_components/nprogress/nprogress.js');
|
||||||
app.import('bower_components/ember-simple-auth/simple-auth.js');
|
|
||||||
app.import('bower_components/ember-simple-auth/simple-auth-oauth2.js');
|
|
||||||
app.import('bower_components/google-caja/html-css-sanitizer-bundle.js');
|
app.import('bower_components/google-caja/html-css-sanitizer-bundle.js');
|
||||||
app.import('bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.js');
|
app.import('bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.js');
|
||||||
app.import('bower_components/codemirror/lib/codemirror.js');
|
app.import('bower_components/codemirror/lib/codemirror.js');
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import ValidationEngine from 'ghost/mixins/validation-engine';
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
||||||
|
|
||||||
export default Ember.Controller.extend(SimpleAuth.AuthenticationControllerMixin, ValidationEngine, {
|
export default Ember.Controller.extend(ValidationEngine, {
|
||||||
needs: 'application',
|
needs: 'application',
|
||||||
|
|
||||||
authenticator: 'simple-auth-authenticator:oauth2-password-grant',
|
|
||||||
|
|
||||||
validationType: 'signin',
|
validationType: 'signin',
|
||||||
|
|
||||||
identification: Ember.computed('session.user.email', function () {
|
identification: Ember.computed('session.user.email', function () {
|
||||||
|
@ -15,11 +13,13 @@ export default Ember.Controller.extend(SimpleAuth.AuthenticationControllerMixin,
|
||||||
actions: {
|
actions: {
|
||||||
authenticate: function () {
|
authenticate: function () {
|
||||||
var appController = this.get('controllers.application'),
|
var appController = this.get('controllers.application'),
|
||||||
|
authStrategy = 'simple-auth-authenticator:oauth2-password-grant',
|
||||||
|
data = this.getProperties('identification', 'password'),
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
appController.set('skipAuthSuccessHandler', true);
|
appController.set('skipAuthSuccessHandler', true);
|
||||||
|
|
||||||
this._super(this.getProperties('identification', 'password')).then(function () {
|
this.get('session').authenticate(authStrategy, data).then(function () {
|
||||||
self.send('closeModal');
|
self.send('closeModal');
|
||||||
self.notifications.showSuccess('Login successful.');
|
self.notifications.showSuccess('Login successful.');
|
||||||
self.set('password', '');
|
self.set('password', '');
|
||||||
|
|
|
@ -2,9 +2,7 @@ import Ember from 'ember';
|
||||||
import ValidationEngine from 'ghost/mixins/validation-engine';
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
||||||
import ajax from 'ghost/utils/ajax';
|
import ajax from 'ghost/utils/ajax';
|
||||||
|
|
||||||
var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControllerMixin, ValidationEngine, {
|
var SigninController = Ember.Controller.extend(ValidationEngine, {
|
||||||
authenticator: 'simple-auth-authenticator:oauth2-password-grant',
|
|
||||||
|
|
||||||
validationType: 'signin',
|
validationType: 'signin',
|
||||||
|
|
||||||
submitting: false,
|
submitting: false,
|
||||||
|
@ -12,9 +10,10 @@ var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControll
|
||||||
actions: {
|
actions: {
|
||||||
authenticate: function () {
|
authenticate: function () {
|
||||||
var model = this.get('model'),
|
var model = this.get('model'),
|
||||||
|
authStrategy = 'simple-auth-authenticator:oauth2-password-grant',
|
||||||
data = model.getProperties('identification', 'password');
|
data = model.getProperties('identification', 'password');
|
||||||
|
|
||||||
this._super(data).catch(function () {
|
this.get('session').authenticate(authStrategy, data).catch(function () {
|
||||||
// if authentication fails a rejected promise will be returned.
|
// if authentication fails a rejected promise will be returned.
|
||||||
// it needs to be caught so it doesn't generate an exception in the console,
|
// 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.
|
// but it's actually "handled" by the sessionAuthenticationFailed action handler.
|
||||||
|
|
|
@ -1,39 +1,20 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import ghostPaths from 'ghost/utils/ghost-paths';
|
import Session from 'simple-auth/session';
|
||||||
|
import OAuth2 from 'simple-auth-oauth2/authenticators/oauth2';
|
||||||
|
|
||||||
var Ghost,
|
var AuthenticationInitializer = {
|
||||||
AuthenticationInitializer;
|
|
||||||
|
|
||||||
Ghost = ghostPaths();
|
|
||||||
|
|
||||||
AuthenticationInitializer = {
|
|
||||||
name: 'authentication',
|
name: 'authentication',
|
||||||
before: 'simple-auth',
|
before: 'simple-auth',
|
||||||
after: 'registerTrailingLocationHistory',
|
after: 'registerTrailingLocationHistory',
|
||||||
|
|
||||||
initialize: function (container) {
|
initialize: function (container) {
|
||||||
window.ENV = window.ENV || {};
|
Session.reopen({
|
||||||
|
|
||||||
window.ENV['simple-auth'] = {
|
|
||||||
authenticationRoute: 'signin',
|
|
||||||
routeAfterAuthentication: 'posts',
|
|
||||||
authorizer: 'simple-auth-authorizer:oauth2-bearer',
|
|
||||||
localStorageKey: 'ghost' + (Ghost.subdir.indexOf('/') === 0 ? '-' + Ghost.subdir.substr(1) : '') + ':session'
|
|
||||||
};
|
|
||||||
|
|
||||||
window.ENV['simple-auth-oauth2'] = {
|
|
||||||
serverTokenEndpoint: Ghost.apiRoot + '/authentication/token',
|
|
||||||
serverTokenRevocationEndpoint: Ghost.apiRoot + '/authentication/revoke',
|
|
||||||
refreshAccessTokens: true
|
|
||||||
};
|
|
||||||
|
|
||||||
SimpleAuth.Session.reopen({
|
|
||||||
user: Ember.computed(function () {
|
user: Ember.computed(function () {
|
||||||
return container.lookup('store:main').find('user', 'me');
|
return container.lookup('store:main').find('user', 'me');
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
SimpleAuth.Authenticators.OAuth2.reopen({
|
OAuth2.reopen({
|
||||||
makeRequest: function (url, data) {
|
makeRequest: function (url, data) {
|
||||||
data.client_id = 'ghost-admin';
|
data.client_id = 'ghost-admin';
|
||||||
return this._super(url, data);
|
return this._super(url, data);
|
||||||
|
|
16
core/client/app/initializers/simple-auth-env.js
Normal file
16
core/client/app/initializers/simple-auth-env.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import ENV from '../config/environment';
|
||||||
|
import ghostPaths from 'ghost/utils/ghost-paths';
|
||||||
|
|
||||||
|
var Ghost = ghostPaths();
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'simple-auth-env',
|
||||||
|
before: 'simple-auth-oauth2',
|
||||||
|
|
||||||
|
initialize: function () {
|
||||||
|
ENV['simple-auth-oauth2'].serverTokenEndpoint = Ghost.apiRoot + '/authentication/token';
|
||||||
|
ENV['simple-auth-oauth2'].serverTokenRevocationEndpoint = Ghost.apiRoot + '/authentication/revoke';
|
||||||
|
|
||||||
|
ENV['simple-auth'].localStorageKey = 'ghost' + (Ghost.subdir.indexOf('/') === 0 ? '-' + Ghost.subdir.substr(1) : '') + ':session';
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,5 +1,8 @@
|
||||||
import Ember from 'ember';
|
|
||||||
/* global key */
|
/* global key */
|
||||||
|
|
||||||
|
import Ember from 'ember';
|
||||||
|
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
|
||||||
|
import Configuration from 'simple-auth/configuration';
|
||||||
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
||||||
import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd';
|
import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd';
|
||||||
|
|
||||||
|
@ -10,7 +13,7 @@ shortcuts.esc = {action: 'closePopups', scope: 'all'};
|
||||||
shortcuts.enter = {action: 'confirmModal', scope: 'modal'};
|
shortcuts.enter = {action: 'confirmModal', scope: 'modal'};
|
||||||
shortcuts[ctrlOrCmd + '+s'] = {action: 'save', scope: 'all'};
|
shortcuts[ctrlOrCmd + '+s'] = {action: 'save', scope: 'all'};
|
||||||
|
|
||||||
ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, ShortcutsRoute, {
|
ApplicationRoute = Ember.Route.extend(ApplicationRouteMixin, ShortcutsRoute, {
|
||||||
shortcuts: shortcuts,
|
shortcuts: shortcuts,
|
||||||
|
|
||||||
afterModel: function (model, transition) {
|
afterModel: function (model, transition) {
|
||||||
|
@ -54,6 +57,10 @@ ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shortcut
|
||||||
this.send('loadServerNotifications', true);
|
this.send('loadServerNotifications', true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
invalidateSession: function () {
|
||||||
|
this.get('session').invalidate();
|
||||||
|
},
|
||||||
|
|
||||||
sessionAuthenticationFailed: function (error) {
|
sessionAuthenticationFailed: function (error) {
|
||||||
if (error.errors) {
|
if (error.errors) {
|
||||||
// These are server side errors, which can be marked as htmlSafe
|
// These are server side errors, which can be marked as htmlSafe
|
||||||
|
@ -83,7 +90,7 @@ ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shortcut
|
||||||
attemptedTransition.retry();
|
attemptedTransition.retry();
|
||||||
self.get('session').set('attemptedTransition', null);
|
self.get('session').set('attemptedTransition', null);
|
||||||
} else {
|
} else {
|
||||||
self.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication);
|
self.transitionTo(Configuration.routeAfterAuthentication);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
var AuthenticatedRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin);
|
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||||
|
|
||||||
|
var AuthenticatedRoute = Ember.Route.extend(AuthenticatedRouteMixin);
|
||||||
|
|
||||||
export default AuthenticatedRoute;
|
export default AuthenticatedRoute;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||||
import MobileIndexRoute from 'ghost/routes/mobile-index-route';
|
import MobileIndexRoute from 'ghost/routes/mobile-index-route';
|
||||||
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
||||||
import mobileQuery from 'ghost/utils/mobile';
|
import mobileQuery from 'ghost/utils/mobile';
|
||||||
|
|
||||||
var PostsIndexRoute = MobileIndexRoute.extend(SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, {
|
var PostsIndexRoute = MobileIndexRoute.extend(AuthenticatedRouteMixin, loadingIndicator, {
|
||||||
noPosts: false,
|
noPosts: false,
|
||||||
|
|
||||||
// Transition to a specific post if we're not on mobile
|
// Transition to a specific post if we're not on mobile
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
import Configuration from 'simple-auth/configuration';
|
||||||
import styleBody from 'ghost/mixins/style-body';
|
import styleBody from 'ghost/mixins/style-body';
|
||||||
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
||||||
|
|
||||||
|
@ -8,7 +9,7 @@ var ResetRoute = Ember.Route.extend(styleBody, loadingIndicator, {
|
||||||
beforeModel: function () {
|
beforeModel: function () {
|
||||||
if (this.get('session').isAuthenticated) {
|
if (this.get('session').isAuthenticated) {
|
||||||
this.notifications.showWarn('You can\'t reset your password while you\'re signed in.', {delayed: true});
|
this.notifications.showWarn('You can\'t reset your password while you\'re signed in.', {delayed: true});
|
||||||
this.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication);
|
this.transitionTo(Configuration.routeAfterAuthentication);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||||
import MobileIndexRoute from 'ghost/routes/mobile-index-route';
|
import MobileIndexRoute from 'ghost/routes/mobile-index-route';
|
||||||
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
|
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
|
||||||
import mobileQuery from 'ghost/utils/mobile';
|
import mobileQuery from 'ghost/utils/mobile';
|
||||||
|
|
||||||
var SettingsIndexRoute = MobileIndexRoute.extend(SimpleAuth.AuthenticatedRouteMixin, CurrentUserSettings, {
|
var SettingsIndexRoute = MobileIndexRoute.extend(AuthenticatedRouteMixin, CurrentUserSettings, {
|
||||||
titleToken: 'Settings',
|
titleToken: 'Settings',
|
||||||
|
|
||||||
// Redirect users without permission to view settings,
|
// Redirect users without permission to view settings,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
import Configuration from 'simple-auth/configuration';
|
||||||
import styleBody from 'ghost/mixins/style-body';
|
import styleBody from 'ghost/mixins/style-body';
|
||||||
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ var SetupRoute = Ember.Route.extend(styleBody, loadingIndicator, {
|
||||||
|
|
||||||
// If user is logged in, setup has already been completed.
|
// If user is logged in, setup has already been completed.
|
||||||
if (this.get('session').isAuthenticated) {
|
if (this.get('session').isAuthenticated) {
|
||||||
this.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication);
|
this.transitionTo(Configuration.routeAfterAuthentication);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
import Configuration from 'simple-auth/configuration';
|
||||||
import styleBody from 'ghost/mixins/style-body';
|
import styleBody from 'ghost/mixins/style-body';
|
||||||
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ var SigninRoute = Ember.Route.extend(styleBody, loadingIndicator, {
|
||||||
|
|
||||||
beforeModel: function () {
|
beforeModel: function () {
|
||||||
if (this.get('session').isAuthenticated) {
|
if (this.get('session').isAuthenticated) {
|
||||||
this.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication);
|
this.transitionTo(Configuration.routeAfterAuthentication);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
import Configuration from 'simple-auth/configuration';
|
||||||
import styleBody from 'ghost/mixins/style-body';
|
import styleBody from 'ghost/mixins/style-body';
|
||||||
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
||||||
|
|
||||||
var SignupRoute = Ember.Route.extend(styleBody, loadingIndicator, {
|
var SignupRoute = Ember.Route.extend(styleBody, loadingIndicator, {
|
||||||
classNames: ['ghost-signup'],
|
classNames: ['ghost-signup'],
|
||||||
|
|
||||||
beforeModel: function () {
|
beforeModel: function () {
|
||||||
if (this.get('session').isAuthenticated) {
|
if (this.get('session').isAuthenticated) {
|
||||||
this.notifications.showWarn('You need to sign out to register as a new user.', {delayed: true});
|
this.notifications.showWarn('You need to sign out to register as a new user.', {delayed: true});
|
||||||
this.transitionTo(SimpleAuth.Configuration.routeAfterAuthentication);
|
this.transitionTo(Configuration.routeAfterAuthentication);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"ember-data": "1.0.0-beta.16.1",
|
"ember-data": "1.0.0-beta.16.1",
|
||||||
"ember-load-initializers": "ember-cli/ember-load-initializers#0.0.2",
|
"ember-load-initializers": "ember-cli/ember-load-initializers#0.0.2",
|
||||||
"ember-resolver": "0.1.15",
|
"ember-resolver": "0.1.15",
|
||||||
"ember-simple-auth": "0.7.2",
|
"ember-simple-auth": "0.8.0-beta.2",
|
||||||
"fastclick": "1.0.6",
|
"fastclick": "1.0.6",
|
||||||
"google-caja": "5669.0.0",
|
"google-caja": "5669.0.0",
|
||||||
"ic-ajax": "2.0.2",
|
"ic-ajax": "2.0.2",
|
||||||
|
|
|
@ -17,6 +17,21 @@ module.exports = function (environment) {
|
||||||
APP: {
|
APP: {
|
||||||
// Here you can pass flags/options to your application instance
|
// Here you can pass flags/options to your application instance
|
||||||
// when it is created
|
// when it is created
|
||||||
|
},
|
||||||
|
|
||||||
|
'simple-auth': {
|
||||||
|
authenticationRoute: 'signin',
|
||||||
|
routeAfterAuthentication: 'posts',
|
||||||
|
authorizer: 'simple-auth-authorizer:oauth2-bearer',
|
||||||
|
|
||||||
|
localStorageKey: '<overriden by initializers/simple-auth-env>'
|
||||||
|
},
|
||||||
|
|
||||||
|
'simple-auth-oauth2': {
|
||||||
|
refreshAccessTokens: true,
|
||||||
|
|
||||||
|
serverTokenEndpoint: '<overriden by initializers/simple-auth-env>',
|
||||||
|
serverTokenRevocationEndpoint: '<overriden by initializers/simple-auth-env>'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,12 @@
|
||||||
"ember-cli-ic-ajax": "0.1.1",
|
"ember-cli-ic-ajax": "0.1.1",
|
||||||
"ember-cli-inject-live-reload": "^1.3.0",
|
"ember-cli-inject-live-reload": "^1.3.0",
|
||||||
"ember-cli-mocha": "^0.5.0",
|
"ember-cli-mocha": "^0.5.0",
|
||||||
"ember-myth": "0.0.2",
|
"ember-cli-simple-auth": "0.8.0-beta.2",
|
||||||
|
"ember-cli-simple-auth-oauth2": "0.8.0-beta.2",
|
||||||
"ember-cli-uglify": "1.0.1",
|
"ember-cli-uglify": "1.0.1",
|
||||||
"ember-data": "1.0.0-beta.16.1",
|
"ember-data": "1.0.0-beta.16.1",
|
||||||
"ember-export-application-global": "^1.0.2",
|
"ember-export-application-global": "^1.0.2",
|
||||||
|
"ember-myth": "0.0.2",
|
||||||
"fs-extra": "0.16.3",
|
"fs-extra": "0.16.3",
|
||||||
"glob": "^4.0.5"
|
"glob": "^4.0.5"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue