IHttpClient Interface

public interface IHttpClient

Interface to be implemented when configuring a custom HTTP client for IPublicClientApplication or IConfidentialClientApplication.

MSAL Java uses HTTP to communicate with the Microsoft identity platform for authentication and token acquisition. By default, MSAL uses the JDK's HttpURLConnection, but this interface allows applications to provide their own HTTP client implementation. This is useful when:

  • Applications need to customize network behavior (e.g., configure proxies, add custom headers)
  • Applications want to use a specific HTTP client library like Apache HttpClient or OkHttp
  • Applications need to integrate with existing network infrastructure or logging systems

For more details, see https://aka.ms/msal4j-http-client

Method Summary

Modifier and Type Method and Description
abstract IHttpResponse send(HttpRequest httpRequest)

Executes an outgoing HTTP request using the HTTP client implementation of choice.

Method Details

send

public abstract IHttpResponse send(HttpRequest httpRequest)

Executes an outgoing HTTP request using the HTTP client implementation of choice.

This method should handle all the details of making the HTTP request and adapting the response to the IHttpResponse interface. The implementation should also include appropriate error handling for network-related issues.

Parameters:

httpRequest - The HttpRequest containing details of the request to execute, including URL, headers, HTTP method, and body.

Returns:

An IHttpResponse object containing the status code, headers, and body of the response.

Throws:

java.lang.Exception - Non-recoverable exceptions that cannot be handled by the HTTP client implementation. Note that recoverable errors (e.g., retryable HTTP status codes, transient network issues) should be handled by the implementation itself.

Applies to