1

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 ToriiAuthenticator from 'ember-simple-auth/authenticators/torii';

export default ToriiAuthenticator.extend({
  torii: Ember.inject.service(),

  authenticate() {
    return this._super(...arguments).then((data) => {
      return new Ember.RSVP.Promise((resolve, reject) => {
        return Ember.$.ajax({
          url: '/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); // => {access_token: ".....", provider: "facebook-oauth2", token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkI…WxsfQ.xx6fBkwqwm7HeoOpnRWRVCKF71DdIhxyQggcfZ6325s", 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.

UPDATE 1: Weirdly, if I include authenticator: 'authenticator:devise' in my '/token' ajax response from the backend, the torii authenticator persists all attributes.

Sbbs
  • 1,610
  • 3
  • 22
  • 34

0 Answers0