Last active
October 8, 2023 13:52
-
-
Save whytarun/36d1f6a5d2d367cfa3b05f4ae5260548 to your computer and use it in GitHub Desktop.
Including support for TLS/SSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Provides | |
fun provideOkhttpClient(authInterceptor: AuthInterceptor, | |
certificateHelper: CertificateHelper | |
) :OkHttpClient{ | |
val trustManagers = certificateHelper.createTrustManagers() | |
val sslContext = SSLContext.getInstance("TLS") | |
sslContext.init(null, trustManagers, null) | |
return OkHttpClient().newBuilder() | |
.readTimeout(2, TimeUnit.MINUTES) | |
.writeTimeout(2, TimeUnit.MINUTES) | |
.connectTimeout(2, TimeUnit.MINUTES) | |
.addInterceptor(authInterceptor) | |
.addInterceptor(loggingInterceptor) | |
.sslSocketFactory(sslContext.socketFactory, | |
trustManagers[0] as X509TrustManager) | |
.build() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment