Search in sources :

Example 1 with HttpClient

use of org.apache.oltu.oauth2.client.HttpClient in project vcita-platform-java-sdk by SimonIT.

the class ApiClient method initHttpClient.

private void initHttpClient(List<Interceptor> interceptors) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.addNetworkInterceptor(getProgressInterceptor());
    for (Interceptor interceptor : interceptors) {
        builder.addInterceptor(interceptor);
    }
    httpClient = builder.build();
}
Also used : TokenRequestBuilder(org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 2 with HttpClient

use of org.apache.oltu.oauth2.client.HttpClient in project vcita-client-java-sdk by SimonIT.

the class ApiClient method initHttpClient.

private void initHttpClient(List<Interceptor> interceptors) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.addNetworkInterceptor(getProgressInterceptor());
    for (Interceptor interceptor : interceptors) {
        builder.addInterceptor(interceptor);
    }
    httpClient = builder.build();
}
Also used : TokenRequestBuilder(org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 3 with HttpClient

use of org.apache.oltu.oauth2.client.HttpClient in project javlo by Javlo.

the class AbstractSocialNetwork method getSocialUser.

public SocialUser getSocialUser(HttpServletRequest request) {
    HttpClient httpClient = null;
    try {
        httpClient = new URLConnectionClient();
        OAuthClient oAuthClient = new OAuthClient(httpClient);
        OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
        String code = oar.getCode();
        String accessToken = getAccessToken(code, oAuthClient);
        TransientUserInfo.getInstance(request.getSession()).setToken(accessToken);
        return getSocialUser(accessToken, oAuthClient);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        if (httpClient != null) {
            httpClient.shutdown();
        }
    }
}
Also used : URLConnectionClient(org.apache.oltu.oauth2.client.URLConnectionClient) OAuthClient(org.apache.oltu.oauth2.client.OAuthClient) HttpClient(org.apache.oltu.oauth2.client.HttpClient) OAuthAuthzResponse(org.apache.oltu.oauth2.client.response.OAuthAuthzResponse) OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) IOException(java.io.IOException) UserAllreadyExistException(org.javlo.user.exception.UserAllreadyExistException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException)

Example 4 with HttpClient

use of org.apache.oltu.oauth2.client.HttpClient in project lusid-sdk-java by finbourne.

the class ApiClient method initHttpClient.

private void initHttpClient(List<Interceptor> interceptors) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.addNetworkInterceptor(getProgressInterceptor());
    for (Interceptor interceptor : interceptors) {
        builder.addInterceptor(interceptor);
    }
    httpClient = builder.build();
}
Also used : TokenRequestBuilder(org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 5 with HttpClient

use of org.apache.oltu.oauth2.client.HttpClient in project javlo by Javlo.

the class AbstractSocialNetwork method performRedirect.

@Override
public void performRedirect(HttpServletRequest request, HttpServletResponse response, boolean admin) {
    HttpClient httpClient = null;
    try {
        httpClient = new URLConnectionClient();
        OAuthClient oAuthClient = new OAuthClient(httpClient);
        OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
        String code = oar.getCode();
        String accessToken = getAccessToken(code, oAuthClient);
        TransientUserInfo.getInstance(request.getSession()).setToken(accessToken);
        SocialUser user = getSocialUser(accessToken, oAuthClient);
        if (user == null || user.getEmail() == null || user.getEmail().isEmpty()) {
            logger.warning("OAuth login failed with provider: " + getName());
            return;
        }
        ContentContext ctx = ContentContext.getContentContext(request, response);
        login(ctx, user, admin);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (httpClient != null) {
            httpClient.shutdown();
        }
    }
}
Also used : URLConnectionClient(org.apache.oltu.oauth2.client.URLConnectionClient) OAuthClient(org.apache.oltu.oauth2.client.OAuthClient) HttpClient(org.apache.oltu.oauth2.client.HttpClient) OAuthAuthzResponse(org.apache.oltu.oauth2.client.response.OAuthAuthzResponse) ContentContext(org.javlo.context.ContentContext) OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) IOException(java.io.IOException) UserAllreadyExistException(org.javlo.user.exception.UserAllreadyExistException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException)

Aggregations

HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)4 TokenRequestBuilder (org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder)4 IOException (java.io.IOException)2 HttpClient (org.apache.oltu.oauth2.client.HttpClient)2 OAuthClient (org.apache.oltu.oauth2.client.OAuthClient)2 URLConnectionClient (org.apache.oltu.oauth2.client.URLConnectionClient)2 OAuthAuthzResponse (org.apache.oltu.oauth2.client.response.OAuthAuthzResponse)2 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)2 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)2 UserAllreadyExistException (org.javlo.user.exception.UserAllreadyExistException)2 ContentContext (org.javlo.context.ContentContext)1