2
有一个使用ember-simple-auth-token请求一个JWT的Ember(v2.12.0-beta.1)应用程序。使用ember-simple-auth-token的令牌请求将不包含标识字段
重要的部分发生在登录控制器。
export default Ember.Controller.extend({
session: Ember.inject.service(),
// Properties
username: 'user1',
password: 'password123',
// Actions
actions: {
login(username, password) {
console.log('Attempting login...');
let creds = this.getProperties('username', 'password');
let authenticator = 'authenticator:jwt';
this.get('session').authenticate(authenticator, creds).then(function() {
console.log('LOGIN SUCCESS')
}, function() {
console.log('LOGIN FAIL')
});
}
}
});
当提交表单时,浏览器会发出一个请求,我的后端会收到它。
问题是只有密码包含在请求中。请求的正文格式为{"password":"password123"}
,但它应该看起来像{"username":"user1","password":"password123"}
。当然,登录尝试失败并打印LOGIN FAIL
。
为什么用户名不包含在令牌请求中?
我尝试使用早期版本的ember-simple-auth-token和ember-simple-auth。
这里是我的配置:
ENV['ember-simple-auth'] = {
authorizer: 'authorizer:token',
};
ENV['ember-simple-auth-token'] = {
serverTokenEndpoint: 'http://127.0.0.1:6003/token',
identificationField: 'username',
passwordField: 'password',
tokenPropertyName: 'token',
authorizationPrefix: 'Bearer ',
authorizationHeaderName: 'Authorization',
refreshAccessTokens: false,
};