-
Notifications
You must be signed in to change notification settings - Fork 147
Configure Http Client
Santiago Gonzalez edited this page Sep 24, 2020
·
4 revisions
To use a custom Http client, you'll need to implement IHttpClient
. This class, which we will class HttpClientAdapter
, should implement send
, which takes in the HttpRequest
composed by MSAL, executes it, and then constructs IHttpResponse
with the results of the execution.
class OkHttpClientAdapter implements IHttpClient{
private OkHttpClient client;
OkHttpClientAdapter(){
// You can configure OkHttpClient
this.client = new OkHttpClient();
}
@Override
public IHttpResponse send(HttpRequest httpRequest) throws IOException {
// Map URL, headers, and body from MSAL's HttpRequest to OkHttpClient request object
Request request = buildOkRequestFromMsalRequest(httpRequest);
// Execute Http request with OkHttpClient
Response okHttpResponse= client.newCall(request).execute();
// Map status code, headers, and response body from OkHttpClient's Response object to MSAL's IHttpResponse
return buildMsalResponseFromOkResponse(okHttpResponse);
}
Once HttpClientAdapter
has been implemented, it can be set on the client application for which you would like to use it.
IHttpClient httpClient = new OkHttpClientAdapter();
PublicClientApplication pca = PublicClientApplication.builder(
APP_ID).
authority(AUTHORITY).
httpClient(httpClient).
build();
All Http requests will now be routed through httpClient
.
- Home
- Why use MSAL4J
- Register your app with AAD
- Scenarios
- Client Applications
- Acquiring tokens
- IAuthenticationResult
- Calling a protected API