I am working on a web app where users can login withe their personal Microsoft. After login I store the access token and the refresh token so that I can later retrieve some data from their Microsoft account.
While the access token is valid, everything works.
final TokenCredential tokenCredential = request -> {
final OffsetDateTime offset = OffsetDateTime.ofInstant(account.getTokenExpiry().toInstant(), ZoneId.systemDefault());
final AccessToken token = new AccessToken(account.getAccessToken(), offset);
return Mono.create(sink -> sink.success(token));
};
final TokenCredentialAuthProvider tokenCredentialAuthProvider =
new TokenCredentialAuthProvider(tokenCredential);
this.graphServiceClient =
GraphServiceClient
.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
The problem is that if the token has expired, I can't just provide the refresh token. I need to first retrieve the new token. Is there a way of doing this? Is there a method where I can just provide both tokens and the refresh is handled automatically?
I could not find anything useful so far.