Graph and Java - Multiple calls against authorization code flow
I am implementing different methods to call Graph API in my Java application. The goal was to use Client Credentials authentication for all requests. Unfortunately this is not possible with the todo tasks (why?). This means that I am forced to use Authorization Code authentication.
My problem is exactly the same as described here: https://stackoverflow.com/questions/69815549/microsoft-graph-and-java-multiple-calls-against-authorization-code-flow
I can't make more than one request with an authorization code. I know that a refresh token has to be used for more requests. But how to do that in Java with AuthorizationCodeCredential?
private GraphServiceClient<Request> getDelegatedGraphClient(String authorizationCode) {
// This client is needed because GraphAPI tasks can't be accessed by application permissions
AuthorizationCodeCredential authCodeCredential = new AuthorizationCodeCredentialBuilder()
.clientId("Id")
.clientSecret("secrect")
.authorizationCode(authorizationCode)
.redirectUrl("url")
.build();
TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(List.of("offline_access","https://graph.microsoft.com/Tasks.ReadWrite"), authCodeCredential);
return GraphServiceClient
.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
}