Search in sources :

Example 16 with ClientRequestFilter

use of javax.ws.rs.client.ClientRequestFilter in project keycloak by keycloak.

the class TwitterShowUserServlet method getTwitterOAuthResponse.

private TwitterOAuthResponse getTwitterOAuthResponse(final HttpServletRequest req) {
    ClientRequestFilter authFilter = new ClientRequestFilter() {

        @Override
        public void filter(ClientRequestContext requestContext) throws IOException {
            KeycloakSecurityContext securityContext = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName());
            String accessToken = securityContext.getTokenString();
            requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken);
        }
    };
    Client client = ClientBuilder.newBuilder().register(authFilter).build();
    WebTarget target = client.target(getIdentityProviderTokenUrl());
    return target.request().get().readEntity(TwitterOAuthResponse.class);
}
Also used : ClientRequestFilter(javax.ws.rs.client.ClientRequestFilter) ClientRequestContext(javax.ws.rs.client.ClientRequestContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Aggregations

ClientRequestFilter (javax.ws.rs.client.ClientRequestFilter)16 Client (javax.ws.rs.client.Client)9 ClientRequestContext (javax.ws.rs.client.ClientRequestContext)9 Response (javax.ws.rs.core.Response)9 Test (org.junit.Test)8 IOException (java.io.IOException)7 WebTarget (javax.ws.rs.client.WebTarget)7 ClientBuilder (javax.ws.rs.client.ClientBuilder)4 ClientResponseFilter (javax.ws.rs.client.ClientResponseFilter)4 Invocation (javax.ws.rs.client.Invocation)3 WebClient (org.apache.cxf.jaxrs.client.WebClient)3 Collections (java.util.Collections)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 HostnameVerifier (javax.net.ssl.HostnameVerifier)2 SSLContext (javax.net.ssl.SSLContext)2 ClientResponseContext (javax.ws.rs.client.ClientResponseContext)2 Entity (javax.ws.rs.client.Entity)2 HttpHeaders (javax.ws.rs.core.HttpHeaders)2 ITHttpAsyncClient (brave.test.http.ITHttpAsyncClient)1