-
Notifications
You must be signed in to change notification settings - Fork 156
Configure Http Client
Santiago Gonzalez edited this page Nov 23, 2019
·
4 revisions
Do use a custom Http client, you'll first need to implement IHttpClient. This class, which we will class HttpClientAdapter for the remainder of this document, should implement a method send. send should take in the HttpRequest composed by MSAL, execute it, and then construct IHttpResponse with the results of the execution.
Once HttpClientAdapter has been implemented, it can be set on the client application for which you would like to use it.
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);
} PublicClientApplication pca = PublicClientApplication.builder(
labResponse.getAppId()).
authority(AUTHORITY).
httpClient( new OkHttpClientAdapter()).
build();- Home
- Why use MSAL4J
- Register your app with AAD
- Scenarios
- Client Applications
- Acquiring tokens
- IAuthenticationResult
- Calling a protected API