由于某种原因未设置“授权”标头。 我试过设置授权器 config / environment.js with
更新:根据@marcoow建议
ENV['simple-auth'] = {
crossOriginWhitelist: ['*'],
authorizer: 'simple-auth-authorizer:devise'
};
ENV['simple-auth-devise'] = {
serverTokenEndpoint: 'users/sign_in',
};
...我可以通过更新其他资源来登录我的应用程序,例如发布授权:Token token =“”,user_email =“”没有被添加到我的服务器调用中
控制器/ dashboard.js
import Ember from 'ember';
export
default Ember.Controller.extend({
actions: {
add: function () {
var name = this.get('name');
var start = this.get('Start');
var end = this.get('End');
var game = this.store.createRecord('game', {
name: name,
start: start,
end: end
});
game.save();
}
}
});
我的请求看起来像这样
** 1。我的立场是这里的请求标题应该包含 授权:标题也是。
登录控制器
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export
default Ember.Controller.extend(LoginControllerMixin, {
authenticator: 'simple-auth-authenticator:devise',
actions: {
authenticate: function () {
console.log('i was called');
var self = this;
var data = this.getProperties('identification', 'password');
self.get('session').authenticate(this.get('authenticator'), data).then(function () {
self.transitionToRoute('dashboard');
}, function (error) {
console.log(error);
});
}
}
});
我可以看到:
如何使用ember-data授权我的Model#save with devise ....
只是为了调试我在route / dashboard.js
中做了这个import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin,{
model: function() {
console.log(this.get('session.isAuthenticated')); # this is true
}
});
答案 0 :(得分:1)
crossOriginWhitelist
不是Devise包的属性 - 您需要为Ember Simple Auth基础包配置它:
ENV['simple-auth'] = {
crossOriginWhitelist: ['*']
};
ENV['simple-auth-devise'] = {
serverTokenEndpoint: 'users/sign_in',
authorizer: 'authorizer:devise'
};
答案 1 :(得分:0)
遇到同样的问题,我的授权标题也没有添加。我的问题是由于Rails的响应验证。在ember-simple-auth中,我将identifyAttributeName设置为" username",但是来自Rails身份验证的json响应(" sessions #create" action)是这样的:{token:&#39 ; xxxxx',user_email:' xxxx' },没有"用户名"字段!
解决了删除" user_email"会话中的字段创建操作的响应,添加"用户名"领域。希望这会有所帮助。