mardi 6 septembre 2016

Issue with persisting session attributes after Torii authentication with ember-simple-auth

I'm following ember-simple-auth dummy app to implement authentication with torii. Everything works, and the app authenticates, but it fails to persist additional attributes returned from the server into data.authenticated. Just as the authentication method expects, I return a promise from the authenticator method with additional attributes token and email to be persisted into the session's data.authenticated:

// ~/frontend/app/authenticators/torii.js

import Ember from 'ember';
import Torii from 'ember-simple-auth/authenticators/torii';

const { inject: { service } } = Ember;

export default Torii.extend({
  torii: service(),
  ajax: service(),

  authenticate() {
    const ajax = this.get('ajax');
    return this._super(...arguments).then((data) => {
      return new Ember.RSVP.Promise((resolve, reject) => {
        return ajax.request('/token', {
          type:     'POST',
          dataType: 'json',
          data:     { 'grant_type': 'facebook_auth_code', 'auth_code': data.authorizationCode, redirect_uri: data.redirectUri  }
        }).then(response => {
          Ember.run(() => {
            Ember.Logger.log('response', response); // => {provider: "facebook-oauth2", token: "...", email: "..@....com"}
            resolve(response);
          });
        }, xhr => {
          Ember.run(() => { reject(xhr.responseJSON || xhr.responseText); });
        });
      });
    });
  }
});

Performing the authentication: this.get('session').authenticate('authenticator:torii', 'facebook-oauth2'); successfully authenticates, but the contents of data.authenticated are only {authenticator: "authenticator:torii", provider: "facebook-oauth2"} while I would expect it to persist token and email as well.

In addition to torii I also have a devise authenticator and it successfully persists additional attributes by default.

I'm using "ember-simple-auth": "1.1.0", ember-data 2.7.0 and ember 2.7.2 all via ember-cli-rails.




Aucun commentaire:

Enregistrer un commentaire