我关注ember-simple-auth
dummy app以使用torii
实施身份验证。一切正常,应用程序进行身份验证,但无法将从服务器返回的其他属性保留到data.authenticated
。正如身份验证方法所期望的那样,我从authenticator方法返回一个承诺,其中包含其他属性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
和authenticator: 'authenticator:devise'
。
更新1:奇怪的是,如果我在后端的'/token'
ajax响应中包含torii
,则object myObj; //this can be anything
PropertyInfo[] properties = myObj.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
}
身份验证器会保留所有属性。