[英]Refreshing the access token from azure ad
I have a scenario where my API updates some claims in active directory via the Graph API.我有一个场景,我的 API 通过图形 API 更新活动目录中的一些声明。
In such case, I notify the client via response headers that it needs to refresh the access token, in order to get a token with the new claims.在这种情况下,我通过响应标头通知客户端它需要刷新访问令牌,以便获得带有新声明的令牌。
The problem is that when I call acquireTokenSilent
(in Msal.UserAgentApplication
) in gives me the old token.问题是,当我调用
acquireTokenSilent
(在Msal.UserAgentApplication
)时,给了我旧令牌。 I found out that it happens because Msal saves the access token in sessionStorage/localStorage.我发现这是因为 Msal 将访问令牌保存在 sessionStorage/localStorage 中。
Is there a way for me to explicitly request a new access token without directly removing the cache?有没有办法让我在不直接删除缓存的情况下显式请求新的访问令牌?
acquireTokenSilent
method will acquire and renew tokens silently in the background. acquireTokenSilent
方法将在后台静默获取和更新令牌。 The access token will expired in an hour by default.默认情况下,访问令牌将在一小时内过期。 After 1 hour, you will get a new access token.
1 小时后,您将获得一个新的访问令牌。 You can refer to this document .
你可以参考这个文档。
Usually we can use the refresh token to refresh access token.通常我们可以使用刷新令牌来刷新访问令牌。 But in msal.js this is not transparent.
但是在 msal.js 中这不是透明的。 Anyway, you can have a look at this answer .
不管怎样,你可以看看这个答案。
You can sign out and sign in again.您可以退出并重新登录。 Then you will get a new access token.
然后您将获得一个新的访问令牌。
You can also call acquireTokenPopup
or acquireTokenRedirect
method to acquire a new access token, but they are interactive methods.您也可以调用
acquireTokenPopup
或acquireTokenRedirect
方法来获取新的访问令牌,但它们是交互式方法。
Refer to How to renew tokens with MSAL.js for more details.有关更多详细信息,请参阅如何使用 MSAL.js 续订令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.