From 62684dffffc70656685ee228a88232e17b20ea48 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) --- core/client/app/authenticators/oauth2.js | 8 ++++++++ core/client/app/controllers/modals/signin.js | 2 +- core/client/app/controllers/reset.js | 2 +- core/client/app/controllers/setup/two.js | 2 +- core/client/app/controllers/signin.js | 2 +- core/client/app/controllers/signup.js | 2 +- core/client/app/initializers/ghost-authenticator.js | 12 ++++++++++++ .../app/instance-initializers/authentication.js | 10 +--------- 8 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 core/client/app/authenticators/oauth2.js create mode 100644 core/client/app/initializers/ghost-authenticator.js diff --git a/core/client/app/authenticators/oauth2.js b/core/client/app/authenticators/oauth2.js new file mode 100644 index 000000000000..ada73d8edaa1 --- /dev/null +++ b/core/client/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/core/client/app/controllers/modals/signin.js b/core/client/app/controllers/modals/signin.js index 4f1e1be7df47..57e02b75f98f 100644 --- a/core/client/app/controllers/modals/signin.js +++ b/core/client/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/core/client/app/controllers/reset.js b/core/client/app/controllers/reset.js index 30c0c27d826a..4123e53a20f5 100644 --- a/core/client/app/controllers/reset.js +++ b/core/client/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/core/client/app/controllers/setup/two.js b/core/client/app/controllers/setup/two.js index 593c32b25095..3cc2cfaf333d 100644 --- a/core/client/app/controllers/setup/two.js +++ b/core/client/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/core/client/app/controllers/signin.js b/core/client/app/controllers/signin.js index 2c3c0d4caf88..8a5cd7680305 100644 --- a/core/client/app/controllers/signin.js +++ b/core/client/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/core/client/app/controllers/signup.js b/core/client/app/controllers/signup.js index 335db1f350d2..6457763b870a 100644 --- a/core/client/app/controllers/signup.js +++ b/core/client/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/core/client/app/initializers/ghost-authenticator.js b/core/client/app/initializers/ghost-authenticator.js new file mode 100644 index 000000000000..9a3538e6f439 --- /dev/null +++ b/core/client/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/core/client/app/instance-initializers/authentication.js b/core/client/app/instance-initializers/authentication.js index 9c7bd2d098a8..3efb1683fb91 100644 --- a/core/client/app/instance-initializers/authentication.js +++ b/core/client/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); - } - }); } };