Ember Simple Auth - 授权人不会在会话恢复时设置

Ember Simple Auth - 授权人不会在会话恢复时设置

问题描述:

下面的代码当前有效,但是如果我使用_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); 
}); 

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

在情况下,它可以帮助任何人,这是我落得这样做。

路线/ 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); 
    } 
});