Search in sources :

Example 1 with OAuth

use of org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth in project product-apim by wso2.

the class ApiClient method setAccessToken.

/**
 * Helper method to pre-set the oauth access token of the first oauth found in the apiAuthorizations (there
 * should be only one)
 *
 * @param accessToken Access Token
 * @param expiresIn   Validity period in seconds
 */
public void setAccessToken(String accessToken, Long expiresIn) {
    for (RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.setAccessToken(accessToken, expiresIn);
            return;
        }
    }
}
Also used : RequestInterceptor(feign.RequestInterceptor) OAuth(org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth)

Example 2 with OAuth

use of org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth 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) OAuth(org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth)

Example 3 with OAuth

use of org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth 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) OAuth(org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth)

Example 4 with OAuth

use of org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth in project carbon-apimgt by wso2.

the class TestMappingUtilTestCase method testSecuritySchemeIntToListMapping.

@Test
void testSecuritySchemeIntToListMapping() {
    int securityScheme = 3;
    List<String> securitySchemeList = MappingUtil.mapSecuritySchemeIntToList(securityScheme);
    List<String> testList = new ArrayList<String>();
    testList.add("Oauth");
    testList.add("apikey");
    assertEquals(securitySchemeList, testList);
}
Also used : ArrayList(java.util.ArrayList) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Example 5 with OAuth

use of org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth in project carbon-apimgt by wso2.

the class TestMappingUtilTestCase method testSecuritySchemeListToIntMapping.

@Test
void testSecuritySchemeListToIntMapping() {
    List<String> testList = new ArrayList<String>();
    testList.add("Oauth");
    testList.add("apikey");
    int securityScheme = MappingUtil.mapSecuritySchemeListToInt(testList);
    assertEquals(securityScheme, 3);
}
Also used : ArrayList(java.util.ArrayList) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)26 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 OAuthApplicationInfo (org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo)13 Map (java.util.Map)11 JSONObject (org.json.simple.JSONObject)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 OAuthApplicationInfo (org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)9 JsonObject (com.google.gson.JsonObject)8 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)8 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)8 TokenResponse (org.wso2.carbon.apimgt.gateway.mediators.oauth.client.TokenResponse)8 LinkedHashMap (java.util.LinkedHashMap)6 Test (org.testng.annotations.Test)6 IOException (java.io.IOException)5 ParseException (org.json.simple.parser.ParseException)5 OAuthAppRequest (org.wso2.carbon.apimgt.api.model.OAuthAppRequest)5 MultiEnvironmentOverview (org.wso2.carbon.apimgt.core.configuration.models.MultiEnvironmentOverview)5 APIMAppConfigurations (org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)5