Skip to content

Commit

Permalink
Merge pull request TryGhost#5756 from kevinansfield/fix-token-refresh…
Browse files Browse the repository at this point in the history
…-issue

Fix auth token refresh failing on app-boot with expired access_token
  • Loading branch information
sebgie committed Aug 28, 2015
2 parents fd3127b + 62684df commit f705798
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
8 changes: 8 additions & 0 deletions core/client/app/authenticators/oauth2.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
2 changes: 1 addition & 1 deletion core/client/app/controllers/modals/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion core/client/app/controllers/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/controllers/setup/two.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/controllers/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/controllers/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
12 changes: 12 additions & 0 deletions core/client/app/initializers/ghost-authenticator.js
Original file line number Diff line number Diff line change
@@ -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
);
}
};
10 changes: 1 addition & 9 deletions core/client/app/instance-initializers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
};

Expand Down

0 comments on commit f705798

Please sign in to comment.