1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00

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)
This commit is contained in:
Kevin Ansfield 2015-08-28 16:00:34 +01:00
parent 685d7ae7a2
commit ac2caa34df
8 changed files with 26 additions and 14 deletions

View file

@ -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);
}
});

View file

@ -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;

View file

@ -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
});

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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
);
}
};

View file

@ -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);
}
});
}
};