Hi,
I am performing an Oauth2.0 flow and am able to get a access and refresh token via a Authorization Code flow. I would then like to use the access token to call the Graph API. The issue is that the accessToken I have is a String, while the API takes a TokenCredential. I made the following class, but it feels a bit odd that this capability does not come 'out of the box' with the API:
import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;
import reactor.core.publisher.Mono;
public class ManualTokenCredential implements TokenCredential {
private final AccessToken accessToken;
public ManualTokenCredential(AccessToken accessToken) {
this.accessToken = accessToken;
}
@Override
public Mono<AccessToken> getToken(TokenRequestContext request) {
return Mono.fromCallable(() -> accessToken);
}
}
See https://learn.microsoft.com/en-us/answers/questions/1555278/how-can-i-initialize-graphserviceclient-by-providi for a C# answer, but I need one in Java.
What is the 'correct' way to do this?