如何通过AMD使用ember-simple-auth进行Ember.SimpleAuth.setup

时间:2014-07-03 01:54:29

标签: ember.js ember-simple-auth

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

谢谢!

1 个答案:

答案 0 :(得分:3)

您现在不能再将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