[英]How to make Ember Cli Mirage to work with Ember Simple auth
For development and testing I want to use Ember CLi Mirage. 为了进行开发和测试,我想使用Ember CLi Mirage。 I'm trying to get it to work with simple auth and oauth2.
我正在尝试使其与简单的auth和oauth2一起使用。 How do I have to set up Mirage to work with a session token?
如何设置Mirage以使用会话令牌?
This is what I'm doing so far: 到目前为止,这是我正在做的事情:
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);
}
}
});
And in mirage I'm not sure how to set up my token route: 在海市rage楼中,我不确定如何设置令牌路径:
this.post('/token');
For custom work like this, pass a function in as the second parameter to your route definition: 对于这样的自定义工作,请将函数 in作为第二个参数传递给您的路由定义:
this.post('/token', function(db, request) {
// generate a token
return {
token: token
};
});
I'd have to know more about your backend to offer more specific guidance, but this is the general idea. 我必须更多地了解您的后端,才能提供更具体的指导,但这是一般的想法。 Hope it helps!
希望能帮助到你!
I use the following in my tests: 我在测试中使用以下内容:
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');
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.