Angular 2 ADAL 令牌刷新,用于隐式流程(使用“adal-angular4”)

2024-02-22

似乎没有实用的方法来刷新隐式流中的令牌。 有人能够实现这一目标吗? MS 文档建议在 Iframe 中进行刷新,寻找有关在 adal ng2 或 adal js 中调用哪些方法的建议!

编辑: 我正在使用这个库https://github.com/benbaran/adal-angular4 https://github.com/benbaran/adal-angular4

编辑:不要使用前面提到的库,它是一个真正的 POS


Using 隐式流动 http://docs.identityserver.io/en/release/topics/grant_types.html您不会刷新当前令牌,您需要获取一个新令牌。

这是我在我的应用程序中处理该问题的方式:

我在用oidc-客户端-js https://github.com/IdentityModel/oidc-client-js. (not adal js)与身份服务器 https://github.com/IdentityServer/IdentityServer4。我的令牌生命周期大约是 20 分钟。因此,为了使客户端的身份验证持续超过 20 分钟,必须在某个时刻请求新令牌。为此,我正在检查用户是否是idle https://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly当他不在时,等等,根据逻辑,可以从身份服务器 https://github.com/IdentityServer/IdentityServer4 using 登录静音 https://github.com/IdentityModel/oidc-client-js/wiki and 自动静默续订 https://github.com/IdentityModel/oidc-client-js/wiki事件。刷新发生在 iframe 中,因为它在oidc-客户端-js https://github.com/IdentityModel/oidc-client-js..

UPDATE:

通过查看adal-Angular4 源 https://github.com/benbaran/adal-angular4/blob/e5073a1d8833113b99b38c567de8be62a90dab08/src/adal-angular.d.ts#L153你需要打电话acquireToken为了更新令牌。根据文档:

/**
* 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;

你可以玩acquireToken使用那个例子https://github.com/benbaran/adal-angular4-example https://github.com/benbaran/adal-angular4-example用它作为this.service.acquireToken(...) in home.component.ts

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angular 2 ADAL 令牌刷新,用于隐式流程(使用“adal-angular4”) 的相关文章

随机推荐