Skip to content

Commit

Permalink
return a promise from OAuth2.Authenticator#refreshAccessToken
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Otte-Witte committed Apr 7, 2014
1 parent de3c178 commit e2dac4d
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,21 @@ var OAuth2 = Ember.SimpleAuth.Authenticators.Base.extend({
refreshAccessToken: function(expiresIn, refreshToken) {
var _this = this;
var data = { grant_type: 'refresh_token', refresh_token: refreshToken };
this.makeRequest(data).then(function(response) {
Ember.run(function() {
expiresIn = response.expires_in || expiresIn;
refreshToken = response.refresh_token || refreshToken;
var expiresAt = _this.absolutizeExpirationTime(expiresIn);
_this.scheduleAccessTokenRefresh(expiresIn, null, refreshToken);
_this.trigger('updated', Ember.$.extend(response, { expires_in: expiresIn, expires_at: expiresAt, refresh_token: refreshToken }));
return new Ember.RSVP.Promise(function(resolve, reject) {
_this.makeRequest(data).then(function(response) {
Ember.run(function() {
expiresIn = response.expires_in || expiresIn;
refreshToken = response.refresh_token || refreshToken;
var expiresAt = _this.absolutizeExpirationTime(expiresIn);
var data = Ember.$.extend(response, { expires_in: expiresIn, expires_at: expiresAt, refresh_token: refreshToken });
_this.scheduleAccessTokenRefresh(expiresIn, null, refreshToken);
_this.trigger('updated', data);
resolve();
});
}, function(xhr, status, error) {
Ember.Logger.warn('Access token could not be refreshed - server responded with ' + error + '.');
reject();
});
}, function(xhr, status, error) {
Ember.Logger.warn('Access token could not be refreshed - server responded with ' + error + '.');
});
},

Expand Down

0 comments on commit e2dac4d

Please sign in to comment.