packages/ember-simple-auth/addon/authenticators/oauth2-password-grant.js
/**
    Restores the session from a session data object; __will return a resolving
    promise when there is a non-empty `access_token` in the session data__ and
    a rejecting promise otherwise.

    If the server issues
    [expiring access tokens](https://tools.ietf.org/html/rfc6749#section-5.1)
    and there is an expired access token in the session data along with a
    refresh token, the authenticator will try to refresh the access token and
    return a promise that resolves with the new access token if the refresh was
    successful. If there is no refresh token or the token refresh is not
    successful, a rejecting promise will be returned.

    @method restore
    @param {Object} data The data to restore the session from
    @return {Ember.RSVP.Promise} A promise that when it resolves results in the session becoming or remaining authenticated. If restoration fails, the promise will reject with the server response (in case the access token had expired and was refreshed using a refresh token); however, the authenticator reads that response already so if you need to read it again you need to clone the response object first
    @public
  */
Restores the session from a session data object; __will return a resolving
promise when there is a non-empty `access_token` in the session data__ and
a rejecting promise otherwise.

If the server issues
[expiring access tokens]
and there is an expired access token in the session data along with a
refresh token, the authenticator will try to refresh the access token and
return a promise that resolves with the new access token if the refresh was
successful. If there is no refresh token or the token refresh is not
successful, a rejecting promise will be returned.
Restores the session from a session data object ; __will return a resolving promise when there is a non - empty ` access_token ` in the session data__ and a rejecting promise otherwise . If the server issues [ expiring access tokens ] and there is an expired access token in the session data along with a refresh token the authenticator will try to refresh the access token and return a promise that resolves with the new access token if the refresh was successful . If there is no refresh token or the token refresh is not successful a rejecting promise will be returned .
restore(data) {
    return new RSVP.Promise((resolve, reject) => {
      const now = (new Date()).getTime();
      const refreshAccessTokens = this.get('refreshAccessTokens');
      if (!isEmpty(data['expires_at']) && data['expires_at'] < now) {
        if (refreshAccessTokens) {
          this._refreshAccessToken(data['expires_in'], data['refresh_token']).then(resolve, reject);
        } else {
          reject();
        }
      } else {
        if (!this._validate(data)) {
          reject();
        } else {
          this._scheduleAccessTokenRefresh(data['expires_in'], data['expires_at'], data['refresh_token']);
          resolve(data);
        }
      }
    });
  }
restore ( data ) { return new RSVP . Promise ( ( resolve , reject ) => { const now = ( new Date ( ) ) . getTime ( ) ; const refreshAccessTokens = this . get ( 'refreshAccessTokens' ) ; if ( ! isEmpty ( data [ 'expires_at' ] ) && data [ 'expires_at' ] < now ) { if ( refreshAccessTokens ) { this . _refreshAccessToken ( data [ 'expires_in' ] , data [ 'refresh_token' ] ) . then ( resolve , reject ) ; } else { reject ( ) ; } } else { if ( ! this . _validate ( data ) ) { reject ( ) ; } else { this . _scheduleAccessTokenRefresh ( data [ 'expires_in' ] , data [ 'expires_at' ] , data [ 'refresh_token' ] ) ; resolve ( data ) ; } } } ) ; }
Restores the session from a session data object; __will return a resolving
promise when there is a non-empty `access_token` in the session data__ and
a rejecting promise otherwise.
Restores the session from a session data object ; __will return a resolving promise when there is a non - empty ` access_token ` in the session data__ and a rejecting promise otherwise .