0
@Singleton
@Provides
fun providesHttpClient(
    logging: HttpLoggingInterceptor,
    @ApplicationContext context: Context,
    authenticator: TokenAuthenticator
): OkHttpClient {
    return OkHttpClient.Builder()
        .addInterceptor(logging)
        .retryOnConnectionFailure(false)
        .readTimeout(30, TimeUnit.SECONDS)
        .connectTimeout(30, TimeUnit.SECONDS) .certificatePinner(CertificatePinner.Builder().add("com.example.domain",CONSTANT.PUBLIC_KEY).build())
        .authenticator(authenticator)
        .build()
}

@Singleton
@Provides
fun providesConvertorFactory(): GsonConverterFactory {
    return GsonConverterFactory.create()
}

@Singleton
@Provides
fun provideRetrofit(
    okHttpClient: OkHttpClient,
    gsonConverterFactory: GsonConverterFactory
): Retrofit {
    return Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(okHttpClient)
        .addConverterFactory(gsonConverterFactory)
        .build()
}

I'm using CertificatePinner with Retrofit for public Key Pinning, Initially the PUBLIC_KEY is empty which will be fetch from server, The key is Fetched but not updating the Singleton

0 Answers0