Angular 2 ADAL令牌刷新,用于隐式流(使用"adal

编程入门 行业动态 更新时间:2024-10-26 05:20:35
本文介绍了Angular 2 ADAL令牌刷新,用于隐式流(使用"adal-angular4")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

似乎没有实用的方法可以刷新隐式流中的令牌. 有没有人能够做到这一点? MS文档建议在iframe中进行刷新,以寻找有关在dal ng2或adal js中进行校准的方法的建议!!!

There seems to be no practical way of refreshing the token in implicit flow. Has anyone been able to achieve this? MS documentation suggests doing the refresh in an Iframe, looking for suggestions of what methods to cal in adal ng2 or adal js!!!

我正在使用这个图书馆 github/benbaran/adal-angular4

I'm using this library github/benbaran/adal-angular4

不要使用上述库,这是一个真正的POS

Don't use the aforementioned library, it's a real POS

推荐答案

使用隐式流,您没有刷新当前令牌,需要获取一个新令牌.

Using implicit flow you are not refreshing the current token, you need to get a new one.

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

Here is how I am handling that in my app:

我正在使用 oidc-client-js (不是adal js) .我的令牌寿命大约为20分钟.因此,为了使客户端的身份验证时间超过20分钟,必须在某个时候请求新令牌.为此,我要检查用户是否 idle ,以及何时否,等等.基于逻辑,可以使用 IdentityServer 获得新令牌"github/IdentityModel/oidc-client-js/wiki" rel ="nofollow noreferrer"> signinSilent 和 automaticSilentRenew 事件.在 oidc-client-js .

I am using oidc-client-js (not adal js) that talks to IdentityServer. I have a token lifetime like 20 minutes. So in order to keep client authenticated for more than 20 minutes the new token has to be requested at some point. In order to do so I am checking if user is idle and when he is not, etc. based on the logic the new token can be obtained form the IdentityServer using signinSilent and automaticSilentRenew events. Refresh happening with iframe as it implemented in oidc-client-js.

通过查看 adal -angular4源,则需要调用acquireToken来续订令牌.根据文档:

By looking in to adal-angular4 source you need to call acquireToken in order to renew the token. As per docs:

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

您可以使用该示例 github/benbaran来玩acquireToken./adal-angular4-example 在homeponent.ts

You can play with acquireToken using that example github/benbaran/adal-angular4-example use it as this.service.acquireToken(...) in homeponent.ts

更多推荐

Angular 2 ADAL令牌刷新,用于隐式流(使用"adal

本文发布于:2023-10-30 23:01:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544254.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   隐式   ADAL   Angular   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!