1

嗨,我正在尝试使用 ember simple auth 编写自己的授权器。但是 Ember-cli 并没有看到它,它仍然在说No authorizer was configured for Ember Simple Auth - specify one if backend requests need to be authorized.

我正在使用 ember-cli 0.1.1

这是我的初始化程序:

var CustomAuthorizer = SimpleAuth.Authorizers.Base.extend({
  authorize: function(jqXHR, requestOptions){
    console.log('authCCC', jqXHR, requestOptions);
  }
});

export default {
  name: 'authorization',
  before: 'simple-auth',
  initialize: function(container, application) {
    container.register('authorizer:custom', CustomAuthorizer);
  }
};

然后根据文档我需要在我的config/environment.js

ENV['simple-auth'] = {
  authorizer: 'authorizer:custom'
};

不知道这里有什么问题。从作者那里,我得到的只是一个没有帮助的文档链接:/

提前致谢。

编辑

这是我的完整 environment.js

module.exports = function(environment) {
  var ENV = {
    modulePrefix: 'app-client',
    environment: environment,
    baseURL: '/',
    locationType: 'auto',
    EmberENV: {
      FEATURES: {
        // Here you can enable experimental features on an ember canary build
        // e.g. 'with-controller': true
      }
    },

    APP: {
      // Here you can pass flags/options to your application instance
      // when it is created
    },
    contentSecurityPolicy: {
      'font-src': "'self' https://fonts.gstatic.com"
    }
  };

  ENV['simple-auth'] = {
    authorizer: 'authorizer:custom'
  };

  if (environment === 'development') {
    ENV.APP.LOG_RESOLVER = true;
    ENV.APP.LOG_ACTIVE_GENERATION = true;
    ENV.APP.LOG_VIEW_LOOKUPS = true;
    ENV.APP.SERVER_URL = 'http://localhost:3000';
    // ENV.APP.SERVER_URL = 'http://0.0.0.0:3000';
  }

  if (environment === 'test') {
    // Testem prefers this...
    ENV.baseURL = '/';
    ENV.locationType = 'auto';

    // keep test console output quieter
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;

    ENV.APP.rootElement = '#ember-testing';
  }

  if (environment === 'staging') {
    ENV.APP.SERVER_URL = 'http://apistaging.server.io';
  }

  if (environment === 'production') {
    ENV.APP.SERVER_URL = 'https://api.server.io';
  }

  return ENV;
};
4

1 回答 1

1

有关与@marcoow 的对话,请参阅上面的评论。基本上这是我的错误。

  • 如果您使用的是 ember-cli,请确保您使用的是简单身份验证的 ember-cli 版本。

  • 确保你已经在你的 environment.js 中注册了授权者,crossOriginWhitelist所以典型的会变成

    ENV['simple-auth'] = { authorizer: 'authorizer:custom', crossOriginWhitelist: ['http://domain.com'] };

这些信息是他的所有文档,但为一个简单身份验证的新手拼凑了一些。

查理

于 2014-11-17T12:31:26.577 回答