com.microsoft.azure.sdk.iot.service.digitaltwin.authentication.ServiceClientCredentialsProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iot-service-client Show documentation
Show all versions of iot-service-client Show documentation
The Microsoft Azure IoT Service SDK for Java
The newest version!
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package com.microsoft.azure.sdk.iot.service.digitaltwin.authentication;
import com.microsoft.rest.credentials.ServiceClientCredentials;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@AllArgsConstructor
public class ServiceClientCredentialsProvider implements ServiceClientCredentials {
private static final String AUTHORIZATION = "Authorization";
@NonNull
private final SasTokenProvider sasTokenProvider;
@Override
public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
Interceptor authenticationInterceptor = chain -> {
Request authenticatedRequest = chain.request()
.newBuilder()
.header(AUTHORIZATION, sasTokenProvider.getSasToken())
.build();
return chain.proceed(authenticatedRequest);
};
clientBuilder.interceptors().add(authenticationInterceptor);
}
}