对于开发和测试,我想使用Ember CLi Mirage。我试图让它与简单的auth和oauth2一起工作。如何设置Mirage以使用会话令牌?
这就是我到目前为止所做的事情:
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
authenticate() {
var data = this.getProperties('username', 'password');
this.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', data);
}
}
});
在海市蜃楼,我不确定如何设置我的令牌路线:
this.post('/token');
答案 0 :(得分:2)
对于这样的自定义工作,pass a function作为路径定义的第二个参数:
this.post('/token', function(db, request) {
// generate a token
return {
token: token
};
});
我必须更多地了解您的后端以提供更具体的指导,但这是一般性的想法。希望它有所帮助!
答案 1 :(得分:2)
我在测试中使用以下内容:
import { test } from 'qunit';
import { authenticateSession } from 'app-name/tests/helpers/ember-simple-auth';
import moduleForAcceptance from 'app-name/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | whatever');
test('visiting /subpage-that-requires-authentication', function(assert) {
authenticateSession(this.application);
visit('subpage-that-requires-authentication');
andThen(function() {
assert.equal(currentURL(), 'subpage-that-requires-authentication');
});
});