2017-09-05 31 views
0

下面的代碼當前有效,但是如果我使用_setup刪除該行,則傳出的請求沒有授權標頭。Ember Simple Auth - 授權人不會在會話恢復時設置

它不覺得我應該使用_setup函數,因爲它不在文檔中。

我在做什麼錯?

我正在使用最新版本的Ember和Ember-Simple-Auth與Oauth Password Grant。

Ember.getOwner(this).lookup('authenticator:custom').restore(token).then(() => { 
    Ember.getOwner(this).lookup('session:main')._setup('authenticator:custom', token, true); 
}); 

回答

0

Restore是一個便利功能,可以在應用程序啓動和存儲更改上運行。據我所知,它並不打算手動調用,但應該在應用程序啓動時自動觸發並從會話數據恢復。無論您通過手動調用還原來嘗試執行什麼操作,都可以在authenticate hook內部處理,將令牌作爲參數傳遞。

到自定義認證者規範的呼叫看起來應該像

session: Ember.inject.service('session'), 
    someFunction() { 
    let token = this.get('tokenSavedSomewhere') 
    this.get('session').authenticate('authenticator:custom', token).catch((reason) => { 
     console.log('Reject reason', reason) 
    }); 
    }, 
+0

這差不多就是我終於實現了。 :) – NotHereAnymore

+1

很酷!感謝您分享您的實施 – handlebears

1

在情況下,它可以幫助任何人,這是我落得這樣做。

路線/ application.js中 (代碼段)

this.get('session').authenticate('authenticator:custom', token).catch((reason) => { 
    console.log('Reject reason', reason) 
})  

鑑別器/ application.js中

export default Authenticator.extend({ 
    authenticate(token) { 
    return this.restore(token); 
    } 
}); 
相關問題