Search in sources :

Example 1 with HttpBasicAuth

use of com.arm.mbed.cloud.sdk.internal.connectorca.auth.HttpBasicAuth in project mbed-cloud-sdk-java by ARMmbed.

the class GsonCustomConverterFactory method setCredentials.

/**
 * Helper method to configure the username/password for basic auth or password oauth
 * @param username Username
 * @param password Password
 * @return ApiClient
 */
public ApiClient setCredentials(String username, String password) {
    for (Interceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof HttpBasicAuth) {
            HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
            basicAuth.setCredentials(username, password);
            return this;
        }
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
            return this;
        }
    }
    return this;
}
Also used : HttpBasicAuth(com.arm.mbed.cloud.sdk.internal.connectorca.auth.HttpBasicAuth) Interceptor(okhttp3.Interceptor) OAuth(com.arm.mbed.cloud.sdk.internal.connectorca.auth.OAuth)

Aggregations

HttpBasicAuth (com.arm.mbed.cloud.sdk.internal.connectorca.auth.HttpBasicAuth)1 OAuth (com.arm.mbed.cloud.sdk.internal.connectorca.auth.OAuth)1 Interceptor (okhttp3.Interceptor)1