From 6989843b19f44ed6908eb9e888ae9f6e0e3e720f Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 28 Aug 2015 16:00:34 +0100 Subject: [PATCH] Fix auth token refresh failing on app-boot with expired access_token issue #5751 - moves `makeRequest` override of simple-auth's OAuth authenticator into our own custom authenticator (previously our override was not taking effect until after ember-simple-auth's initial authentication routines, hence why it was working for post-login token refreshes but failing on app-boot) --- ghost/admin/app/authenticators/oauth2.js | 8 ++++++++ ghost/admin/app/controllers/modals/signin.js | 2 +- ghost/admin/app/controllers/reset.js | 2 +- ghost/admin/app/controllers/setup/two.js | 2 +- ghost/admin/app/controllers/signin.js | 2 +- ghost/admin/app/controllers/signup.js | 2 +- ghost/admin/app/initializers/ghost-authenticator.js | 12 ++++++++++++ .../app/instance-initializers/authentication.js | 10 +--------- 8 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 ghost/admin/app/authenticators/oauth2.js create mode 100644 ghost/admin/app/initializers/ghost-authenticator.js diff --git a/ghost/admin/app/authenticators/oauth2.js b/ghost/admin/app/authenticators/oauth2.js new file mode 100644 index 0000000000..ada73d8eda --- /dev/null +++ b/ghost/admin/app/authenticators/oauth2.js @@ -0,0 +1,8 @@ +import Authenticator from 'simple-auth-oauth2/authenticators/oauth2'; + +export default Authenticator.extend({ + makeRequest: function (url, data) { + data.client_id = 'ghost-admin'; + return this._super(url, data); + } +}); diff --git a/ghost/admin/app/controllers/modals/signin.js b/ghost/admin/app/controllers/modals/signin.js index 4f1e1be7df..57e02b75f9 100644 --- a/ghost/admin/app/controllers/modals/signin.js +++ b/ghost/admin/app/controllers/modals/signin.js @@ -15,7 +15,7 @@ export default Ember.Controller.extend(ValidationEngine, { actions: { authenticate: function () { var appController = this.get('application'), - authStrategy = 'simple-auth-authenticator:oauth2-password-grant', + authStrategy = 'ghost-authenticator:oauth2-password-grant', data = this.getProperties('identification', 'password'), self = this; diff --git a/ghost/admin/app/controllers/reset.js b/ghost/admin/app/controllers/reset.js index 30c0c27d82..4123e53a20 100644 --- a/ghost/admin/app/controllers/reset.js +++ b/ghost/admin/app/controllers/reset.js @@ -45,7 +45,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}); - self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', { + self.get('session').authenticate('ghost-authenticator:oauth2-password-grant', { identification: self.get('email'), password: credentials.newPassword }); diff --git a/ghost/admin/app/controllers/setup/two.js b/ghost/admin/app/controllers/setup/two.js index 593c32b250..3cc2cfaf33 100644 --- a/ghost/admin/app/controllers/setup/two.js +++ b/ghost/admin/app/controllers/setup/two.js @@ -75,7 +75,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('simple-auth-authenticator:oauth2-password-grant', { + self.get('session').authenticate('ghost-authenticator:oauth2-password-grant', { identification: self.get('email'), password: self.get('password') }).then(function () { diff --git a/ghost/admin/app/controllers/signin.js b/ghost/admin/app/controllers/signin.js index 2c3c0d4caf..8a5cd76803 100644 --- a/ghost/admin/app/controllers/signin.js +++ b/ghost/admin/app/controllers/signin.js @@ -17,7 +17,7 @@ export default Ember.Controller.extend(ValidationEngine, { authenticate: function () { var self = this, model = this.get('model'), - authStrategy = 'simple-auth-authenticator:oauth2-password-grant', + authStrategy = 'ghost-authenticator:oauth2-password-grant', data = model.getProperties('identification', 'password'); this.get('session').authenticate(authStrategy, data).then(function () { diff --git a/ghost/admin/app/controllers/signup.js b/ghost/admin/app/controllers/signup.js index 335db1f350..6457763b87 100644 --- a/ghost/admin/app/controllers/signup.js +++ b/ghost/admin/app/controllers/signup.js @@ -64,7 +64,7 @@ export default Ember.Controller.extend(ValidationEngine, { }] } }).then(function () { - self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', { + self.get('session').authenticate('ghost-authenticator:oauth2-password-grant', { identification: self.get('model.email'), password: self.get('model.password') }).then(function () { diff --git a/ghost/admin/app/initializers/ghost-authenticator.js b/ghost/admin/app/initializers/ghost-authenticator.js new file mode 100644 index 0000000000..9a3538e6f4 --- /dev/null +++ b/ghost/admin/app/initializers/ghost-authenticator.js @@ -0,0 +1,12 @@ +import GhostOauth2Authenticator from 'ghost/authenticators/oauth2'; + +export default { + name: 'ghost-authentictor', + + initialize: function (container) { + container.register( + 'ghost-authenticator:oauth2-password-grant', + GhostOauth2Authenticator + ); + } +}; diff --git a/ghost/admin/app/instance-initializers/authentication.js b/ghost/admin/app/instance-initializers/authentication.js index 9c7bd2d098..3efb1683fb 100644 --- a/ghost/admin/app/instance-initializers/authentication.js +++ b/ghost/admin/app/instance-initializers/authentication.js @@ -5,21 +5,13 @@ var AuthenticationInitializer = { initialize: function (instance) { var store = instance.container.lookup('store:main'), - Session = instance.container.lookup('simple-auth-session:main'), - OAuth2 = instance.container.lookup('simple-auth-authenticator:oauth2-password-grant'); + Session = instance.container.lookup('simple-auth-session:main'); Session.reopen({ user: Ember.computed(function () { return store.find('user', 'me'); }) }); - - OAuth2.reopen({ - makeRequest: function (url, data) { - data.client_id = 'ghost-admin'; - return this._super(url, data); - } - }); } };