2

I have tried to follow some of the examples online, but they are not very helpful and the official Microsoft documentation can be somewhat confusing and all over the place.

I have the token, which includes the nonce in the header.

I have added in the Microsoft Graph dependency in my pom.xml file and everything is set up, but I am not sure how to actually implement the method using the access token and make the calle to get a the signed in user info for example.

https://graph.microsoft.com/v1.0/me

I have set up my app in Azure already and added in the API permissions.

any help or guidance in the right direction would be helpful.

1 Answer 1

3

You could refer to the example of signed-in user request, see here.

IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();

// for "/me" endpoint    
User user = graphClient.me().buildRequest().get(); 

// for "/users/{id | userPrincipalName}" endpoint
// User user = graphClient.users("{id}").buildRequest().get() 

Get authProvider with accessToken, refer to this article:

public IGraphServiceClient getAuthProvider() {
    IAuthenticationProvider mAuthenticationProvider;

    try {
        String accessToken = "xxxxxxxxxxxxx";
        mAuthenticationProvider = request -> request.addHeader("Authorization", "Bearer " + accessToken);
    } catch (Exception e) {
        throw new Error("Could not create a graph client: " + e.getLocalizedMessage());
    }

    return GraphServiceClient.builder()
                             .authenticationProvider(mAuthenticationProvider)
                             .buildClient();
}

For more information, Make API calls using the Microsoft Graph SDKs with Java.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank You! That helped me alot
After adding a bunch of heavy dependencies like MS Graph and Azure Identity SDK, I still had to resort to crafting pure HTTP POST calls in JAX-RS for requesting AcessToken and overriding the authentication provider for the simplest authentication mechanism of all times. So thank you for this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.