Search in sources :

Example 96 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory 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
 * @return ApiClient
 */
public ApiClient setAccessToken(String accessToken) {
    for (Interceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.setAccessToken(accessToken);
            return this;
        }
    }
    return this;
}
Also used : Interceptor(okhttp3.Interceptor) OAuth(com.arm.mbed.cloud.sdk.internal.iam.auth.OAuth)

Example 97 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory method configureAuthorizationFlow.

/**
 * Helper method to configure the oauth accessCode/implicit flow parameters
 * @param clientId Client ID
 * @param clientSecret Client secret
 * @param redirectURI Redirect URI
 * @return ApiClient
 */
public ApiClient configureAuthorizationFlow(String clientId, String clientSecret, String redirectURI) {
    for (Interceptor 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 this;
        }
    }
    return this;
}
Also used : Interceptor(okhttp3.Interceptor) OAuth(com.arm.mbed.cloud.sdk.internal.iam.auth.OAuth)

Example 98 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory method registerAccessTokenListener.

/**
 * Configures a listener which is notified when a new access token is received.
 * @param accessTokenListener Access token listener
 * @return ApiClient
 */
public ApiClient registerAccessTokenListener(AccessTokenListener accessTokenListener) {
    for (Interceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.registerAccessTokenListener(accessTokenListener);
            return this;
        }
    }
    return this;
}
Also used : Interceptor(okhttp3.Interceptor) OAuth(com.arm.mbed.cloud.sdk.internal.iam.auth.OAuth)

Example 99 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory method registerAccessTokenListener.

/**
 * Configures a listener which is notified when a new access token is received.
 * @param accessTokenListener Access token listener
 * @return ApiClient
 */
public ApiClient registerAccessTokenListener(AccessTokenListener accessTokenListener) {
    for (Interceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.registerAccessTokenListener(accessTokenListener);
            return this;
        }
    }
    return this;
}
Also used : Interceptor(okhttp3.Interceptor) OAuth(com.arm.mbed.cloud.sdk.internal.connectorca.auth.OAuth)

Example 100 with Interceptor

use of com.pushtorefresh.storio3.Interceptor in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory method configureAuthorizationFlow.

/**
 * Helper method to configure the oauth accessCode/implicit flow parameters
 * @param clientId Client ID
 * @param clientSecret Client secret
 * @param redirectURI Redirect URI
 * @return ApiClient
 */
public ApiClient configureAuthorizationFlow(String clientId, String clientSecret, String redirectURI) {
    for (Interceptor 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 this;
        }
    }
    return this;
}
Also used : Interceptor(okhttp3.Interceptor) OAuth(com.arm.mbed.cloud.sdk.internal.devicedirectory.auth.OAuth)

Aggregations

Interceptor (okhttp3.Interceptor)138 Request (okhttp3.Request)61 OkHttpClient (okhttp3.OkHttpClient)54 Response (okhttp3.Response)51 IOException (java.io.IOException)45 Test (org.junit.Test)29 Retrofit (retrofit2.Retrofit)27 File (java.io.File)15 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)13 Cache (okhttp3.Cache)9 HttpUrl (okhttp3.HttpUrl)8 Interceptor (com.pushtorefresh.storio3.Interceptor)7 Dispatcher (okhttp3.Dispatcher)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 X509TrustManager (javax.net.ssl.X509TrustManager)6 CachingAuthenticator (com.burgstaller.okhttp.digest.CachingAuthenticator)5 Provides (dagger.Provides)5 Singleton (javax.inject.Singleton)5 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)5 OAuth (com.arm.mbed.cloud.sdk.internal.devicedirectory.auth.OAuth)4