2

I have a custom authenticator which is really just extending the oauth2 authenticator so I can pass additional infomration to the API with my POST to /token.

All works fine. However, when you do a page refresh and the session tries to restore I am redirected to the login page and not authenticated.

The restore() method, if still within expiry and has a token should and does resolve with data however this does not authenticate the session.

Any ideas?

restore: function(data) {
var _this = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
  var now = (new Date()).getTime();
  if (!Ember.isEmpty(data.expires_at) && data.expires_at < now) {
    if (_this.refreshAccessTokens) {
      _this.refreshAccessToken(data.expires_in, data.refresh_token).then(function(data) {
        resolve(data);
      }, reject);
    } else {
      reject();
    }
  } else {
    if (Ember.isEmpty(data.access_token)) {
      reject();
    } else {
      _this.scheduleAccessTokenRefresh(data.expires_in, data.expires_at, data.refresh_token);
      Ember.run(function() {
        log('returning restore')
        log(data) //shows my previous session data including access_token
        resolve(data);
      })
    }
  }
});
},
LukeC
  • 111
  • 5
  • What does the session data look like before the refresh? – marcoow Dec 12 '15 at 13:40
  • `{ "secure": { "authenticator": "simple-auth-authenticator:oauth2-password-grant", "access_token": "accesstokenstring", "token_type": "Bearer", "expires_in": 45000, "refresh_token": "", "expires_at": 1450131023288 } }` – LukeC Dec 14 '15 at 09:42
  • Plus I also have some ofther data stored not in secure like the currentUser and the currentProfile – LukeC Dec 14 '15 at 09:43
  • I also get this error `Cannot read property 'send' of undefined` – LukeC Dec 14 '15 at 12:33
  • It seems the latter error was caused by me having a beforeModel hook in my application route, and callling ```this._super();``` without passing in `````this._super(transition)````` – LukeC Dec 15 '15 at 10:10
  • I have upgraded to latest version from 0.8 and it seems to solve my problem – LukeC Dec 16 '15 at 09:20
  • @LukeC where do you override `restore`? In your custom authenticators extending `'ember-simple-auth/authenticators/base'` ? – andilabs Jun 20 '16 at 13:16

0 Answers0