我正在使用 azure-identity
库对用户进行身份验证,以便在我的 Spring Boot Web 应用程序中访问 Microsoft Graph API。
通过身份验证代码授予重定向成功获取code
后,我想将访问 token 和刷新 token 存储在Web应用程序 session 中,以便用户不必重新进行身份验证向 Microsoft Graph API 发出多个请求。
如何获取 token 并将其存储在 session 中?
最佳答案
授权代码是用于获取实际访问 token 的单用户代码。您需要将该代码
兑换为access_token
,如 Microsoft identity platform and OAuth 2.0 authorization code flow 中所述。 .
包含 access_token
的响应正文还将包含 refresh_token
值:
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1Q...",
"token_type": "Bearer",
"expires_in": 3599,
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4...",
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctOD...",
}
关于spring-boot - 在 Web 应用程序 session 中存储 AuthorizationCodeCredential,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69030231/