4

我尝试使用ToriiSimple-Auth Torii authenticationator设置 facebook 登录。我正在使用 ember-cli。

这是我的配置:

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

这是我的登录代码:

// 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);
        }
      );
    }
  }
});

弹出窗口正在打开请求授权,然后我看到带有“SUCCESS UNDEFINED”的警报。我想我会得到一些我可以在我的后端使用的数据来肯定地验证用户(访问令牌或 facebook uid 等......)。

我是否错过了将 Torii 与 Simple-Auth 一起使用的方式?

4

1 回答 1

4

返回的承诺Session#authenticate没有值,但是一旦通过身份验证,torii 身份验证器解析的所有内容都可以通过会话获得(在您的情况下,返回的承诺已经解决)。你可以访问例如一个token属性

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

您还可以检查会话的content属性(您不应该使用它,因为它是私有的,但可以进行调试)以找出可用的内容:

console.log(this.get('session.content'))
于 2014-09-11T08:22:56.930 回答