【问题标题】:How to do Ember.SimpleAuth.setup using ember-simple-auth via AMD如何通过 AMD 使用 ember-simple-auth 执行 Ember.SimpleAuth.setup
【发布时间】:2014-07-03 01:54:28
【问题描述】:

在使用 ember-cli-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
  }
};

谢谢!

【问题讨论】:

    标签: ember.js ember-simple-auth


    【解决方案1】:

    您不能再调用SimpleAuth.setup,因为它现在是私有 API。如果您使用的是 Ember CLI,只需安装 Ember CLI 插件:https://github.com/simplabs/ember-cli-simple-auth。如果您使用的是 EAK(在这种情况下,无论如何您都应该迁移到 Ember CLI),请确保您需要 Ember Simple Auth 自动加载器:

    require('simple-auth/ember');

    还可以查看自述文件中的安装说明:https://github.com/simplabs/ember-simple-auth#installation

    在这两种情况下,您都不必致电SimpleAuth.setup。如果你想注册你的自定义验证器,只需添加一个在“simple-auth”初始化器之前运行的初始化器:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多