在使用Torii身份验证中获取currentUser?

时间:2015-07-23 23:56:29

标签: facebook authentication ember.js ember-simple-auth

尝试更改torii身份验证器以从响应中返回帐户ID,因此在会话中可用于获取帐户。

在尝试使示例适应torii身份验证器时,我有这个起点(显然是错误的,达到我的js知识限制):

import Ember from 'ember';
import Torii from 'simple-auth-torii/authenticators/torii';
import Configuration from 'simple-auth-oauth2/configuration';

export default Torii.extend({
  authenticate: function(credentials) {
    return this._super(provider).then((authResponse) => {
      return new Ember.RSVP.Promise(function(resolve, reject) {
        Ember.$.ajax({
          url:  Configuration.serverTokenEndpoint,
          type: 'POST',
          data: { 'auth_code': authResponse.authorizationCode }
        }).then(function(response) {
          Ember.run(function() {
            // all properties this promise resolves
            // with will be available through the session
            resolve({ access_token: response.access_token, account_id: response.account_id });
          });
        }, function(xhr, status, error) {
          Ember.run(function() {
            reject(xhr.responseText);
          });
        });
      });
    });
  }
});

Ember不会抱怨任何错误,但当然facebook的auth对话框不会弹出。在这一点上迷失了,任何指针都会非常感激。

更新

这是提供商代码,在更改身份验证器以尝试返回account_id之前正在运行:

import Ember from 'ember';
import FacebookOauth2 from 'torii/providers/facebook-oauth2';

let { resolve } = Ember.RSVP;

export default FacebookOauth2.extend({
  fetch(data) {
    return resolve(data);
  },

  close() {
    return resolve();
  }
});

这是以前的工作身份验证器:

import Ember from 'ember';
import Torii from 'simple-auth-torii/authenticators/torii';
import Configuration from 'simple-auth-oauth2/configuration';

export default Torii.extend({
  authenticate(provider) {
    return this._super(provider).then((authResponse) => {
      return Ember.$.post(Configuration.serverTokenEndpoint, { 'auth_code': authResponse.authorizationCode }).then(function(response) {
        return { 'access_token': response['access_token'], provider };
      });
    });
  }
});

0 个答案:

没有答案