1

我正在关注ember-simple-auth 虚拟应用程序来实现身份验证torii。一切正常,应用程序进行身份验证,但它无法将从服务器返回的其他属性保存到data.authenticated. 正如身份验证方法所期望的那样,我从身份验证器方法返回一个带有附加属性的承诺,token并将email其持久化到会话中data.authenticated

// ~/frontend/app/authenticators/torii.js

import Ember from 'ember';
import ToriiAuthenticator from 'ember-simple-auth/authenticators/torii';

export default ToriiAuthenticator.extend({
  torii: Ember.inject.service(),

  authenticate() {
    return this._super(...arguments).then((data) => {
      return new Ember.RSVP.Promise((resolve, reject) => {
        return Ember.$.ajax({
          url: '/token',
          type:     'POST',
          dataType: 'json',
          data:     { 'grant_type': 'facebook_auth_code', 'auth_code': data.authorizationCode, redirect_uri: data.redirectUri  }
        }).then(response => {
          Ember.run(() => {
            Ember.Logger.log('response', response); // => {access_token: ".....", provider: "facebook-oauth2", token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkI…WxsfQ.xx6fBkwqwm7HeoOpnRWRVCKF71DdIhxyQggcfZ6325s", email: "..@....com"}
            resolve(response);
          });
        }, xhr => {
          Ember.run(() => { reject(xhr.responseJSON || xhr.responseText); });
        });
      });
    });
  }
});

执行身份验证:this.get('session').authenticate('authenticator:torii', 'facebook-oauth2');成功进行身份验证,但内容data.authenticated{authenticator: "authenticator:torii", provider: "facebook-oauth2"}在我希望它持续存在token的情况下email

除了torii我还有一个devise身份验证器,它默认成功地保留了其他属性。

我正在使用"ember-simple-auth": "1.1.0", ember-data 2.7.0并且ember 2.7.2全部通过ember-cli-rails.

更新 1:奇怪的是,如果我authenticator: 'authenticator:devise''/token'后端的 ajax 响应中包含,torii验证器会保留所有属性。

4

0 回答 0