4
votes

I tried to setup a facebook login using Torii and Simple-Auth Torii authenticator. I am using ember-cli.

Here is my configuration :

// config/environment.js
ENV['torii'] = {
    providers: {
        'facebook-oauth2': {
            apiKey:      'my facebook app id'
        }
    }
}

Here is my login code :

// app/controllers/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';

export default Ember.Controller.extend(LoginControllerMixin, {
  actions: {
    authenticateWithTorii: function(){
      this.get('session').authenticate(
        'simple-auth-authenticator:torii',
        'facebook-oauth2'
      ).then(
        function(data) {
          alert('SUCCESS ' + data);
        },
        function(error) {
          alert('There was an error when trying to sign you in: ' + error);
        }
      );
    }
  }
});

The popup is opening asking for authorization, then I see the alert with "SUCCESS UNDEFINED". I thought I will get some data I could use on my backend to definitely authentify the user (access token or facebook uid, etc...).

Did I miss something in the way to use Torii with Simple-Auth ?

1

1 Answers

4
votes

The promise returned by Session#authenticatedoes not have a value but everything that the torii authenticator resolves with is available via the session as soon as that's authenticated (which it is in your case as the returned promise has resolved). You could access e.g. a token property with

var _this = this;
this.get('session').authenticate(
  'simple-auth-authenticator:torii',
  'facebook-oauth2'
).then(function(data) {
  alert('SUCCESS ' + _this.get('session.token'));
})

You can also inspect the session's content property (which you shouldn't use otherwise as it's private but for debugging that's ok) to find out what's available:

console.log(this.get('session.content'))