0

Our Front End using PKCE flow and fetches a access Token. As per the old implementation ([email protected] version) this below snippet gets a Graph Client using an existing access token. Now I cannot get the same working in the newer MS Graph Java SDK.

IGraphServiceClient client = GraphServiceClient.builder()
                        .authenticationProvider( request -> request.addHeader("Authorization", "Bearer " + tokenAuthentication.getToken().getTokenValue()) )
                        .buildClient(); 

Dependencies I have added to my project

<dependency>
            <!-- Include the sdk as a dependency -->
            <groupId>com.microsoft.graph</groupId>
            <artifactId>microsoft-graph</artifactId>
            <version>5.13.0</version>
        </dependency>
        <dependency>
            <!-- This dependency is only needed if you are using the TokenCrendentialAuthProvider -->
            <groupId>com.azure</groupId>
            <artifactId>azure-identity</artifactId>
            <version>1.2.5</version>
        </dependency>

1 Answer 1

1

finally got it working.. see below snippet..

IAuthenticationProvider authProvider = new IAuthenticationProvider() {
            
            @Override
            public CompletableFuture<String> getAuthorizationTokenAsync(URL requestUrl) {
                CompletableFuture<String> future = new CompletableFuture<>();
                future.complete(yourToken);
                return future;
            }
        };
        
        GraphServiceClient<Request> graphClient = GraphServiceClient
                .builder()
                .authenticationProvider(authProvider)
                .buildClient();

         return graphClient.me().buildRequest().get();
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.