private Http buildHttpRequest(final String format) throws Exception {
        val originalHost = SpringExpressionLanguageValueResolver.getInstance().resolve(getDuoClient().getDuoApiHost());
        val host = new URI(StringUtils.prependIfMissing(originalHost, "https://"));
        val request = new CasHttpBuilder(HttpMethod.POST.name(),
            host.getHost(), String.format(format, AUTH_API_VERSION)).build();

        val hostField = ReflectionUtils.findField(request.getClass(), "host");
        ReflectionUtils.makeAccessible(Objects.requireNonNull(hostField));

        val resultingHost = host.getHost() + (host.getPort() > 0 ? ":" + host.getPort() : StringUtils.EMPTY);
        ReflectionUtils.setField(hostField, request, resultingHost);

        val factory = httpClient.httpClientFactory();
        val clientInstanceBuilder = new OkHttpClient.Builder()
            .connectTimeout(DEFAULT_HTTP_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .readTimeout(DEFAULT_HTTP_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .writeTimeout(DEFAULT_HTTP_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .hostnameVerifier(factory.getHostnameVerifier());
        if ("localhost".equalsIgnoreCase(host.getHost())) {
            clientInstanceBuilder
                .certificatePinner(CertificatePinner.DEFAULT)
                .sslSocketFactory(factory.getSslContext().getSocketFactory(), (X509TrustManager) factory.getTrustManagers()[0]);
        } else {
            val pinner = getDuoClient().createCertificatePinner(host.getHost(), request);
            clientInstanceBuilder.certificatePinner(pinner);
        }
        val httpClientField = ReflectionUtils.findField(Http.class, "httpClient");
        ReflectionUtils.makeAccessible(Objects.requireNonNull(httpClientField));

        val clientInstance = clientInstanceBuilder.build();
        ReflectionUtils.setField(httpClientField, request, clientInstance);
        return request;
    }
This is {@link BaseDuoSecurityAuthenticationService}.

@author Misagh Moayyed
@since 5.1.0
support/cas-server-support-duo-core/src/main/java/org/apereo/cas/adaptors/duo/authn/BaseDuoSecurityAuthenticationService.java