Getting Connection Reset Issue while Fetching Azure Access Token

Rahul Kapoor 21 Reputation points

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 failed. 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("").build();

ClientCredentialParameters clientCredentialParam = ClientCredentialParameters.builder(Collections.singleton(String.format(;

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.


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

    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:

    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