ember-simple-auth-torii Facebook provider never returns promise from open function

228 views Asked by At

I'm using ember-simple-auth-torii with a custom Facebook OAuth2 authenticator, but I never seem to be able to have the promise return any data (for the data.authorizationCode). The popup window just hangs until I close it, at which point I get the popupClosed error message.

What am I missing that I should be doing?

Thanks!

FacebookAuthenticator = OAuth2.extend
  torii: null
  provider: "facebook-oauth2"
  authenticate: (credentials) ->
    that = this
    new Ember.RSVP.Promise((resolve, reject) ->
      that.torii.open(that.provider).then((data) ->
        data =
          facebook_auth_code: data.authorizationCode
        that.makeRequest(that.serverTokenEndpoint, data).then ((response) ->
          Ember.run ->
            expiresAt = that.absolutizeExpirationTime(response.expires_in)
            that.scheduleAccessTokenRefresh response.expires_in, expiresAt, response.refresh_token
            resolve Ember.$.extend(response,
              expires_at: expiresAt,
              access_token: response.access_token,
              user_id: response.user_id
            )
        ), (xhr) ->
          Ember.run ->
            reject xhr.responseJSON or xhr.responseText
        )
      )

FacebookAuthentication =
  name: "facebook-authentication"
  before: "simple-auth"
  after: 'torii'
  initialize: (container) ->
    Session.reopen
      user: (->
        userId = @get('user_id')
        if (!Ember.isEmpty(userId))
          return container.lookup('store:main').find('user', userId)
      ).property('userId')
    torii = container.lookup('torii:main')
    authenticator = FacebookAuthenticator.create
      torii: torii
    container.register("authenticator:facebook", authenticator, {
      instantiate: false  
    })

`export default FacebookAuthentication`
1

There are 1 answers

0
Josh Smith On BEST ANSWER

The problem I was having was with an incorrect URL.

You need to set the URL in Facebook's advanced app settings, and ensure it is the same URL as your ember-cli app as specified in redirectUri.

Facebook settings