2014-10-19 70 views
0

我已经升级了一个用于simple-auth的自定义身份验证器和授权程序的ember-cli应用程序,从0.0.40和ember-cli-simple-auth 0.6.3到版本0.0 .46和0.6.7。授权()方法不会触发CustomAuthorizer

身份验证可以正常工作,但authorize()方法不会触发,所以安全令牌不会添加到头并返回http 401错误。

我在其他地方看,这可能是一个缺乏crossOriginWhitelist问题的,但我有这个在我的index.html:

<script> 
    window.EmberENV = {{EMBER_ENV}}; 
    <!-- Ember Simple Auth relies on window.ENV to read its configuration --> 
    window.ENV = window.EmberENV; 
    window.ENV['simple-auth'] = { 
     authorizer: 'authorizer:custom', 
    crossOriginWhitelist: window.EmberENV.APP.crossOriginWhitelist 
    }; 
</script> 

这似乎没什么问题。

我可以在我的beforeModel()授权检查添加这Ajax调用消除401错误:

  beforeSend: function (request) 
      { 
       request.setRequestHeader('Authorization', 'Bearer ' + self.get('session.token')); 
      }, 

但这是不正确的,当然,它只是一个创可贴。

任何人有任何想法?

感谢,

BillyB

+0

灰烬简单验证不读window.ENV的煨了,但使用灰烬CLI时使用你的应用程序的糖渍从配置/ environment.js。 – marcoow 2014-10-20 06:27:44

回答

0

我发现这个问题。

除升级ember-cli版本之外,我做的唯一更改是从ember-simple-auth切换为ember-cli-simple-auth,即将Ember Simple Auth基本库打包为Ember CLI Addon。

后者在ember-cli的environment.js中接受其配置,而不是在index.html中的内联脚本中,正如我上面所做的那样。这工作:

ENV['simple-auth'] = { 
     authenticationRoute: 'login', 
     routeAfterAuthentication: 'index', 
     routeIfAlreadyAuthenticated: 'index', 
     authorizer: 'authorizer:custom', 
     crossOriginWhitelist: ENV.APP.crossOriginWhitelist 

请注意simple-auth的人:这没有很好的记录,或至少我错过了它。

-BillyB

相关问题