我正在尝试使用ember-simple-auth实现自定义身份验证,并且我在开始时陷入困境。我有app / autheticators / digest.js
import Base from 'ember-simple-auth/authenticators/base';
import Ember from 'ember';
export default Base.extend({
restore(data) {
//
},
authenticate(email, password) {
console.log(email, password);
return new Ember.RSVP.Promise(function(resolve, reject) {
Ember.run(function() {
resolve({email: email, password: password});
});
});
},
invalidate(data) {
//
}
});
应用程序/授权人/ digest.js
import Base from 'simple-auth/authorizers/base';
import Ember from 'ember';
export default Base.extend({
header: function() {
return "test-digest";
},
authorize: function(sessionData, block) {
console.log('authorize...');
block('Authorization', this.get('header'));
}
});
登录组件:
import Ember from 'ember';
import CryptoJS from 'npm:crypto-js';
export default Ember.Component.extend({
session: Ember.inject.service('session'),
actions: {
login() {
let { email, password } = this.getProperties('email', 'password');
this.get("session").authenticate('autheticator:digest',
email, CryptoJS.SHA256(password).toString()).catch((reason) => {
this.set('errorMessage', reason.error);
});
}
}
});
身份验证调用正确(我希望),但授权人中的“授权”从未调用过。我还尝试向ENV添加一些值:
ENV['simple-auth'] = {
authorizer: 'authorizer:digest',
crossOriginWhitelist: ['http://prod-drunkedguru.rhcloud.com:80/'] // ['*'] I also tried
};
但没有改变。我做错了什么?
P.S。我正在使用EmberJS 1.13.0和EAS 1.0。
答案 0 :(得分:1)
我假设您正在使用ESA 1.0。在该版本中,授权者不再被自动调用,但您需要手动调用它。您可以使用DataAdapterMixin
自动授权Ember Data请求。有关迁移到1.0的指导,请参阅此博文:http://log.simplabs.com/post/131698328145/updating-to-ember-simple-auth-10