2014-10-19 41 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

相關問題