【发布时间】:2015-04-30 01:14:58
【问题描述】:
我一直在努力找出我错过了什么;我正在使用simple-auth 和simple-auth-token 库(通过ember-cli 0.2.3)并且似乎无法让我的应用程序设置适当的Athentication: HTTP 标头。根据我的阅读,最常见的疏忽是人们没有在simple-auth ENV 变量上设置crossOriginWhitelist: 属性。但是,即使值为['*'],我似乎也无法让 Ember 将标头与我的 API 请求一起发送。请注意,我正在替换以前的手动(虽然,半生不熟!)身份验证解决方案,所以我知道我的 API 服务器可以工作,并且将在正确的凭据下进行身份验证。
当我运行login 操作时,一切正常。如果我在那之后点击了受保护的 Ember 路线,它也可以正常工作。当Ember-data 尝试访问我的 API(http://localhost:3000)时,问题就来了;它返回一个401(因为它没有设置Authorization: 标头)并转换到我网站的索引。
以下是相关的代码部分:
config/environments.js
...
ENV['simple-auth'] = {
authenticationRoute: 'login',
authorizer: 'simple-auth-authorizer:token',
crossOriginWhitelist: ['*']
};
ENV['simple-auth-token'] = {
identificationField: 'email',
passwordField: 'password',
tokenPropertyName: 'token',
authorizationPrefix: 'Bearer ',
authorizationHeaderName: 'Authorization'
};
...
routes/login.js
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
login: function(){
var creds = this.controller.getProperties('identification', 'password');
this.get('session').authenticate('simple-auth-authenticator:jwt', creds)
.then(function() {
// +
}, function() {
// -
});
}
}
});
routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin);
提前致谢。
【问题讨论】:
标签: ember.js ember-simple-auth