Getting Connection Reset Issue while Fetching Azure Access Token

Rahul Kapoor 21 Reputation points
2020-12-08T07:21:01.06+00:00

hope everyone is well.

I am using azure library to fetch access token using the below code snippet, but getting an error

Execution of class com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier failed.
com.microsoft.aad.msal4j.MsalClientException: java.net.SocketException: Connection reset

When I enclose the code in try catch, it gets catched as an ExecutionException.
Below is the code snippet.

ConfidentialClientApplication app = ConfidentialClientApplication.builder("XXX", ClientCredentialFactory.createFromCertificate(XXX, "")).authority("https://login.microsoftonline.com/XXX").build();


ClientCredentialParameters clientCredentialParam = ClientCredentialParameters.builder(Collections.singleton(String.format(https://graph.microsoft.com/.default))).build();


CompletableFuture future = app.acquireToken(clientCredentialParam);

//call to future.get() function

I appreciate if anyone could help me in this issue as I am unable to find any solution for this for the past 2 weeks, tried so many ways but no success.

Thanks

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,337 questions
{count} votes

Accepted answer
  1. soumi-MSFT 11,716 Reputation points Microsoft Employee
    2020-12-08T09:12:07.05+00:00

    Hello @Rahul Kapoor , thank you for reaching out. I just see the ConfidentialClientApplication class being used here. To understand this better I would suggest debugging your code to check if there is any specific message being passed while your ExecutionException error gets caught in the catch block.

    Also, here in the code try updating line 7 to CompletableFuture<IAuthenticationResult> future = app.acquireToken(clientCredentialParam);
    Also, I would suggest taking a look at the following sample: https://github.com/Azure-Samples/ms-identity-java-daemon/tree/master/msal-client-credential-certificate/src/main/java

    This also uses client_credentials flow with certificates.

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as an Answer; if the above response helped in answering your query.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful