首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过AMD使用ember实现Ember.SimpleAuth.setup

如何通过AMD使用ember实现Ember.SimpleAuth.setup
EN

Stack Overflow用户
提问于 2014-07-03 01:54:28
回答 1查看 749关注 0票数 1

在使用ember simple-auth之前,我使用了这个初始化器:

代码语言:javascript
复制
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'
    });
  }
});

现在如何做到这一点,在使用导入时,我已经讲到了重点:

代码语言:javascript
复制
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
  }
};

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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’初始化器之前运行的初始化程序:

代码语言:javascript
复制
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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24543777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档