Facebook login with Torii and Simple-Auth : no authentication data returned

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 16:31:51

问题


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:


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'))


来源:https://stackoverflow.com/questions/25775463/facebook-login-with-torii-and-simple-auth-no-authentication-data-returned

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!