Angular 2 ADAL令牌刷新,用于隐式流(使用"adal-angular4") [英] Angular 2 ADAL token refresh, for implicit flow (using "adal-angular4")

查看:206
本文介绍了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!!!

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

I'm using this library https://github.com/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 获得新令牌"https://github.com/IdentityModel/oidc-client-js/wiki" rel ="nofollow noreferrer"> signinSilent 和 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;

您可以使用该示例 https://github.com/benbaran来玩acquireToken./adal-angular4-example home.component.ts

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

这篇关于Angular 2 ADAL令牌刷新,用于隐式流(使用"adal-angular4")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆