Search in sources :

Example 16 with RequestInterceptor

use of feign.RequestInterceptor in project product-apim by wso2.

the class ApiClient method setApiKey.

/**
 * Helper method to configure the first api key found
 *
 * @param apiKey API key
 */
public void setApiKey(String apiKey) {
    for (RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof ApiKeyAuth) {
            ApiKeyAuth keyAuth = (ApiKeyAuth) apiAuthorization;
            keyAuth.setApiKey(apiKey);
            return;
        }
    }
    throw new RuntimeException("No API key authentication configured!");
}
Also used : RequestInterceptor(feign.RequestInterceptor)

Example 17 with RequestInterceptor

use of feign.RequestInterceptor in project product-apim by wso2.

the class ApiClient method registerAccessTokenListener.

/**
 * Configures a listener which is notified when a new access token is received.
 *
 * @param accessTokenListener Acesss token listener
 */
public void registerAccessTokenListener(AccessTokenListener accessTokenListener) {
    for (RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.registerAccessTokenListener(accessTokenListener);
            return;
        }
    }
}
Also used : RequestInterceptor(feign.RequestInterceptor)

Example 18 with RequestInterceptor

use of feign.RequestInterceptor in project product-apim by wso2.

the class ApiClient method setCredentials.

/**
 * Helper method to configure the username/password for basic auth or password OAuth
 *
 * @param username Username
 * @param password Password
 */
public void setCredentials(String username, String password) {
    for (RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof HttpBasicAuth) {
            HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
            basicAuth.setCredentials(username, password);
            return;
        }
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
            return;
        }
    }
    throw new RuntimeException("No Basic authentication or OAuth configured!");
}
Also used : RequestInterceptor(feign.RequestInterceptor)

Example 19 with RequestInterceptor

use of feign.RequestInterceptor in project product-apim by wso2.

the class ApiClient method configureAuthorizationFlow.

/**
 * Helper method to configure the oauth accessCode/implicit flow parameters
 *
 * @param clientId     Client ID
 * @param clientSecret Client secret
 * @param redirectURI  Redirect URI
 */
public void configureAuthorizationFlow(String clientId, String clientSecret, String redirectURI) {
    for (RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.getTokenRequestBuilder().setClientId(clientId).setClientSecret(clientSecret).setRedirectURI(redirectURI);
            oauth.getAuthenticationRequestBuilder().setClientId(clientId).setRedirectURI(redirectURI);
            return;
        }
    }
}
Also used : RequestInterceptor(feign.RequestInterceptor)

Example 20 with RequestInterceptor

use of feign.RequestInterceptor in project feign by OpenFeign.

the class ReactiveFeignIntegrationTest method testRequestInterceptor.

@Test
public void testRequestInterceptor() {
    this.webServer.enqueue(new MockResponse().setBody("1.0"));
    RequestInterceptor mockInterceptor = mock(RequestInterceptor.class);
    TestReactorService service = ReactorFeign.builder().requestInterceptor(mockInterceptor).target(TestReactorService.class, this.getServerUrl());
    StepVerifier.create(service.version()).expectNext("1.0").expectComplete().verify();
    verify(mockInterceptor, times(1)).apply(any(RequestTemplate.class));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RequestTemplate(feign.RequestTemplate) RequestInterceptor(feign.RequestInterceptor) Test(org.junit.Test)

Aggregations

RequestInterceptor (feign.RequestInterceptor)20 OAuth (org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth)4 BasicAuthRequestInterceptor (feign.auth.BasicAuthRequestInterceptor)3 RequestTemplate (feign.RequestTemplate)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 Test (org.junit.Test)2 ApiKeyAuth (org.wso2.carbon.apimgt.rest.integration.tests.store.auth.ApiKeyAuth)1 HttpBasicAuth (org.wso2.carbon.apimgt.rest.integration.tests.store.auth.HttpBasicAuth)1