currentUser fetched in Authentication with Torii?

﹥>﹥吖頭↗ 提交于 2019-12-12 00:25:34

问题


Trying to change a torii authenticator to return an account id from the response, so it's available in the session for fetching the account.

In trying to adapt the example to the torii authenticator, I have this starting point (obviously wrong, hitting on my js knowledge limits):

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 doesn't complain with any errors, but of course facebook's auth dialog doesn't pop. Lost at this point, any pointers would be greatly appreciated.

Update

This is the provider code, which was working before changing the authenticator to try and return the account_id as well:

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

This is the previous, working authenticator:

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

来源:https://stackoverflow.com/questions/31600037/currentuser-fetched-in-authentication-with-torii

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