Search code examples
facebookauthenticationember.jsember-simple-auth

ember-simple-auth facebook authenticator


Trying to hook up facebook authentication for my app. I've got the backend working correctly but my authenticator (I think this is the problem) is always returning undefined.

Copying the example from from ember-simple-auth the console log on line 23 is never called, making me think something else the issue?

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 ajax.request('http://localhost:8080/api/login', {
        type: 'POST',
        dataType: 'application/json',
        data: {
          'grant_type': 'facebook_auth_code',
          'auth_code': data.authorizationCode
        }
      }).then((response) => {

        console.log("CALLED!");

        return {
          access_token: response,
          provider: data.provider
        };
      });
    });
  }
});

The response from the server is the access_token from facebook;

How can I better debug/solve what's going on here?


Solution

  • The problem was actually a simple error with the dataType used. It should be dataType: 'json' not dataType: 'application/json'