简体   繁体   English

从 azure 广告刷新访问令牌

[英]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.您也可以调用acquireTokenPopupacquireTokenRedirect方法来获取新的访问令牌,但它们是交互式方法。

Refer to How to renew tokens with MSAL.js for more details.有关更多详细信息,请参阅如何使用 MSAL.js 续订令牌

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Cordova-app中从Azure AD获取access_token - Get access_token from Azure AD in Cordova-app Azure AD使用刷新令牌访问使用JavaScript的访问令牌 - Azure AD using refresh token to access access token using javascript 使用Azure AD身份验证库(角度5中的ADAL)获取Id_token,但是如何从Id_token获取访问令牌? - getting Id_token using Azure AD Authentication Library(ADAL in angular 5), but how to get access token from Id_token? 获取访问令牌和登录时出现Azure AD错误 - Azure AD error when fetching access token & login 刷新帐户工具包访问令牌 - Refreshing Account Kit access token 用于Azure AD v2登录的JavaScript OAuth2流未提供access_token - JavaScript OAuth2 flow for Azure AD v2 login does not give an access_token 如何在没有任何用户的情况下从Azure AD应用程序中使用Javascript在SPFX或Sharepoint页面中使用client_id和client_secret从Azure AD应用程序读取访问令牌? - How to read the access token without any user from Azure AD Application using client_id and client_secret in SPFX or Sharepoint Page using Javascript? 如何为 Power Bi 报告获取 ServicePrincipal 的 azure AD access_token - how to get azure AD access_token for ServicePrincipal for power bi reports 使用 Javascript SDK 刷新 FB 访问令牌 - Refreshing FB Access Token with Javascript SDK 刷新长寿命访问令牌端点是否在 2021 年工作? - Is refreshing long lived access token endpoint working in 2021?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM