在使用ember simple-auth之前,我使用了这个初始化器:
Ember.Application.initializer({
name: 'authentication',
initialize: function(container, application) {
container.register('authenticator:api', Oauth2Authenticator);
Ember.SimpleAuth.setup(container, application, {
authorizerFactory: 'ember-simple-auth-authorizer:oauth2-bearer',
routeAfterAuthentication: 'dashboard',
routeAfterInvalidation: 'login',
storeFactory: 'ember-simple-auth-session-store:local-storage'
});
}
});现在如何做到这一点,在使用导入时,我已经讲到了重点:
import Oauth2Authenticator from '../services/authenticator';
export default {
name: 'authentication',
initialize: function(container, app) {
container.register('authenticator:api', Oauth2Authenticator);
// THIS PART IS NOT CLEAR, HOW TO SETUP IN AMD?
Ember.SimpleAuth.setup(container, application, {
authorizerFactory: 'ember-simple-auth-authorizer:oauth2-bearer',
routeAfterAuthentication: 'dashboard',
routeAfterInvalidation: 'login',
storeFactory: 'ember-simple-auth-session-store:local-storage'
});
// END OF CONFUSING PART
}
};谢谢!
发布于 2014-07-03 06:57:36
您不能再调用SimpleAuth.setup了,因为它现在是私有API。如果您使用的是Ember,只需安装Ember插件:https://github.com/simplabs/ember-cli-simple-auth。如果您正在使用EAK (在这种情况下,您应该迁移到Ember CLI ),请确保需要Ember Simple Auth autoloader:
require('simple-auth/ember');
还请查看自述文件中的安装说明:https://github.com/simplabs/ember-simple-auth#installation
在这两种情况下,您都不必调用SimpleAuth.setup。如果您想注册您的自定义身份验证器,只需添加一个在‘simple’初始化器之前运行的初始化程序:
import Oauth2Authenticator from '../services/authenticator';
export default {
name: 'authentication',
before: 'simple-auth',
initialize: function(container, app) {
container.register('authenticator:api', Oauth2Authenticator);
}
};现在通过全局ENV对象完成配置-参见API文档这里:http://ember-simple-auth.simplabs.com/ember-simple-auth-api-docs.html#SimpleAuth-Configuration
https://stackoverflow.com/questions/24543777
复制相似问题