1

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

谢谢!

4

1 回答 1

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

于 2014-07-03T06:57:36.357 回答