简体   繁体   English

如何在 msal 中使用刷新令牌更新我的访问令牌?

[英]How do I update my access token with a refresh token in msal?

I used B2C and MSAL to configure the SPA certification.我使用 B2C 和 MSAL 配置 SPA 认证。 Then, the backend API access token, refresh token, and ID token are obtained from B2C and stored in localstorage.然后从B2C获取后端API access token、refresh token、ID token存储到localstorage中。 However, after about an hour I noticed that the access token was disabled.但是,大约一个小时后,我注意到访问令牌被禁用了。 At this time, I believe I can use a refresh token to update my access token.这时,我相信我可以使用刷新令牌来更新我的访问令牌。 I am a beginner and would be grateful if you could give me a sample or something.我是初学者,如果您能给我样品或其他东西,我将不胜感激。 Thank you in advance.先感谢您。

MSAL takes care of refresh token for you. MSAL 会为您处理刷新令牌。 What you should do is always ask a token from MSAL before using one.您应该做的是在使用令牌之前始终向 MSAL 索取令牌。 If it needs to refresh it using a refresh token, it will just do that behind the scenes.如果它需要使用刷新令牌刷新它,它会在幕后进行。

You can see an example here: https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-spa-acquire-token .您可以在此处查看示例: https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-spa-acquire-token There it shows a general pattern where you first try acquireTokenSilent, and if that fails, use a popup/redirect to get new tokens.它显示了一个一般模式,您首先尝试 acquireTokenSilent,如果失败,则使用弹出/重定向来获取新令牌。

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

相关问题 如何将刷新令牌与获取访问令牌分开? - how can I Separate Refresh token with Get access token? 如何刷新 Microsoft Graph 访问令牌 - How To Refresh Microsoft Graph Access Token 如何刷新通过 Azure 身份验证收到的访问令牌? - How to refresh access token received with Azure authentication? 如何从未经身份验证的 Cognito 身份获取访问令牌 - How do I obtain an Access Token from an Unauthenticated Cognito Identity 如何在 gcloud 中使用访问令牌 - How can I use an access token with gcloud 错误:invalid_grant,用于使用刷新令牌获取访问令牌 - error: invalid_grant , for getting access token using refresh token 如何在 Flutter 上刷新 firebase 令牌? - How to refresh firebase token on Flutter? 如何更新 FCM 令牌 - How to update FCM token MSAL - 如何使用 Angular 13 兼容的 MSAL 库获取 ID 令牌 - MSAL - How to get ID token using Angular 13 compatible MSAL Library 如何使用 REST API 从服务帐户凭据创建访问令牌? - How do I create an Access Token from Service Account Credentials using REST API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM