jeudi 23 juillet 2015

currentUser fetched in Authentication with Torii?

Trying to change a torii authenticator to return an account id from the response, so it's available in the session for fetching the account.

In trying to adapt the example to the torii authenticator, I have this starting point (obviously wrong, hitting on my js knowledge limits):

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

export default Torii.extend({
  authenticate: function(credentials) {
    return this._super(provider).then((authResponse) => {
      return new Ember.RSVP.Promise(function(resolve, reject) {
        Ember.$.ajax({
          url:  Configuration.serverTokenEndpoint,
          type: 'POST',
          data: { 'auth_code': authResponse.authorizationCode }
        }).then(function(response) {
          Ember.run(function() {
            // all properties this promise resolves
            // with will be available through the session
            resolve({ access_token: response.access_token, account_id: response.account_id });
          });
        }, function(xhr, status, error) {
          Ember.run(function() {
            reject(xhr.responseText);
          });
        });
      });
    });
  }
});

Ember doesn't complain with any errors, but of course facebook's auth dialog doesn't pop. Lost at this point, any pointers would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire