Search in sources :

Example 1 with OAuth

use of io.swagger.client.auth.OAuth in project android-client by GenesisVision.

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(io.swagger.client.auth.OAuth)

Example 2 with OAuth

use of io.swagger.client.auth.OAuth in project android-client by GenesisVision.

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(io.swagger.client.auth.OAuth)

Example 3 with OAuth

use of io.swagger.client.auth.OAuth in project android-client by GenesisVision.

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(io.swagger.client.auth.HttpBasicAuth) Interceptor(okhttp3.Interceptor) OAuth(io.swagger.client.auth.OAuth)

Example 4 with OAuth

use of io.swagger.client.auth.OAuth in project android-client by GenesisVision.

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(io.swagger.client.auth.OAuth)

Aggregations

OAuth (io.swagger.client.auth.OAuth)4 Interceptor (okhttp3.Interceptor)4 HttpBasicAuth (io.swagger.client.auth.HttpBasicAuth)1