0

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.

Update

This is the provider code, which was working before changing the authenticator to try and return the account_id as well:

import Ember from 'ember';
import FacebookOauth2 from 'torii/providers/facebook-oauth2';

let { resolve } = Ember.RSVP;

export default FacebookOauth2.extend({
  fetch(data) {
    return resolve(data);
  },

  close() {
    return resolve();
  }
});

This is the previous, working authenticator:

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

export default Torii.extend({
  authenticate(provider) {
    return this._super(provider).then((authResponse) => {
      return Ember.$.post(Configuration.serverTokenEndpoint, { 'auth_code': authResponse.authorizationCode }).then(function(response) {
        return { 'access_token': response['access_token'], provider };
      });
    });
  }
});
oliverbarnes
  • 2,111
  • 1
  • 20
  • 31
  • 2
    When Facebook's auth dialog doesn't show sth. is wrong with the provider - probably a misconfiguration or so. You'd want to step into the provider's `open` method with the debugger. – marcoow Jul 24 '15 at 09:26
  • Have you tried with multiple browsers? I wonder whether you're blocking pop-ups. – brian Jul 24 '15 at 18:42
  • @brian yes, tried it with Chrome Canary, Safari and Firefox – oliverbarnes Jul 25 '15 at 10:21
  • @marcoow I added the code for the provider, and the previous authenticator, with which the former worked ok. I'm guessing it's something in the new resolving of promises by the new authenticator that's breaking it – oliverbarnes Jul 25 '15 at 10:28

0 Answers0