似乎没有实用的方法来刷新隐式流中的 token 。 有人能够实现这一目标吗? MS 文档建议在 Iframe 中进行刷新,寻找有关在 adal ng2 或 adal js 中调用哪些方法的建议!!!
编辑: 我正在使用这个库 https://github.com/benbaran/adal-angular4
编辑:不要使用上述库,它是一个真正的 POS
最佳答案
使用implicit flow您没有刷新当前 token ,您需要获取一个新 token 。
以下是我在应用程序中处理该问题的方法:
我正在使用oidc-client-js (不是 adal js
)与 IdentityServer 对话。我的 token 生命周期大约是 20 分钟。因此,为了使客户端的身份验证持续超过 20 分钟,必须在某个时刻请求新 token 。为此,我正在检查用户是否是 idle当他不在时,等等,根据逻辑,可以从 IdentityServer 获取新 token 。使用signinSilent和 automaticSilentRenew事件。刷新发生在 iframe 中,因为它在 oidc-client-js 中实现.
更新:
通过查看adal-angular4 source您需要调用 acquireToken
来更新 token 。根据文档:
/**
* Acquire token from cache if not expired and available. Acquires token from iframe if expired.
* @param {string} resource ResourceUri identifying the target resource
* @param {requestCallback} callback
*/
acquireToken(resource: string, callback: (message: string, token: string) => any): void;
您可以使用该示例 https://github.com/benbaran/adal-angular4-example 来使用 acquireToken
将其用作 home.component.ts
this.service.acquireToken(...)
关于Angular 2 ADAL token 刷新,用于隐式流程(使用 "adal-angular4"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45517630/