Search code examples
spring-bootmicrosoft-graph-apiazure-identity

storing AuthorizationCodeCredential in web app session


I am using the azure-identity library to authenticate users for accessing the Microsoft Graph API in my Spring Boot web application.

After getting the successfully getting the code via auth code grant redirect I want to store the access token and refresh token in the the web application session so that the user does not have to re-authenticate for doing multiple requests to the Microsoft Graph API.

How can I get hold of the tokens for storing them in the session?


Solution

  • The way to do this was to create a class that implements OAuth2AuthorizedClientService that stores and loads the OAuth credentials in the database.