Share via

I am using MSAL4J java library to authenticate to Microsoft using certificate, need help to configure proxy server configuration.

Anonymous
2023-12-08T19:17:01+00:00

I am using MSAL4J java library to authenticate to Microsoft using certificate, my code is working fine but I want my code to use proxy server for authentication.

I found https://learn.microsoft.com/en-us/entra/msal/java/advanced/configure-http-client but not able modify the class to use proxy configuration.

Below is my code, kindly let me know what should I do.

private static IAuthenticationResult getAccessTokenByClientCredentialGrant(String authority, String clientId, String keystorePath, String certPath, String scope, String keystorepwd, String keystorealias, String proxy, String pUsr, String pPwd) 

        throws FileNotFoundException, IOException, Exception 

    {

        KeyStore keyStore = KeyStore.getInstance("PKCS12");

        //InputStream keyStoreData = new FileInputStream(keystorePath);

        InputStream keyStoreData = null;

        try {

            keyStoreData = new FileInputStream(keystorePath);

            keyStore.load(keyStoreData, keystorepwd.toCharArray());

        } finally {

            if (keyStoreData != null) {

                try {

                    keyStoreData.close();

                } catch (IOException e) {

                    throw e;

                }

            }

        }

        PrivateKey key = (PrivateKey) keyStore.getKey(keystorealias, keystorepwd.toCharArray());

        InputStream certStream = new ByteArrayInputStream(Files.readAllBytes(Paths.get(certPath)));

        X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(certStream);

        ConfidentialClientApplication  app = ConfidentialClientApplication.builder(

                        clientId,

                        ClientCredentialFactory.createFromCertificate(key, cert))

                        .authority(authority)

                        .build();

            }

        ClientCredentialParameters clientCredentialParam = ClientCredentialParameters.builder(

                Collections.singleton(scope))

                .build();

        CompletableFuture<IAuthenticationResult> future = app.acquireToken(clientCredentialParam);

        return future.get();

    }

Microsoft 365 and Office | Install, redeem, activate | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-12-08T22:09:32+00:00

    Dear Abhijit NagleGI,

    Good day! Thank you for posting to Microsoft Community. We are happy to help you!

    Given your question about using MSAL4J java library to authenticate to Microsoft using certificate, and the current forum channel you're posting focuses on Microsoft 365 for Business, especially Exchange Online builds.

    Therefore, in order to get further dedicated technical support and assistance, to help you better and not waste more time, it is recommended to publish a new thread on the Microsoft Q&A forum with java library and proxy server tags. Dedicated support engineers there specialize in work related to Azure AD and will provide you with further assistance with your current goals/deployments.

    Thanks in advance for your understanding! Your patience and cooperation will be highly appreciated. Hope you all the best!

    Was this answer helpful?

    0 comments No comments