Search in sources :

Example 11 with OAuthClient

use of org.apache.oltu.oauth2.client.OAuthClient in project structr by structr.

the class StructrOAuthClient method getAccessTokenResponse.

private OAuthAccessTokenResponse getAccessTokenResponse(final HttpServletRequest request) {
    if (tokenResponse != null) {
        return tokenResponse;
    }
    try {
        String code = getCode(request);
        if (code == null) {
            logger.error("Could not get code from request, cancelling authorization process");
            return null;
        }
        OAuthClientRequest clientReq = OAuthClientRequest.tokenLocation(tokenLocation).setGrantType(getGrantType()).setClientId(clientId).setClientSecret(clientSecret).setRedirectURI(getAbsoluteUrl(request, redirectUri)).setCode(getCode(request)).buildBodyMessage();
        logger.info("Request body: {}", clientReq.getBody());
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        tokenResponse = oAuthClient.accessToken(clientReq, tokenResponseClass);
        logger.info("Access token response: {}", tokenResponse.getBody());
        return tokenResponse;
    } catch (Throwable t) {
        logger.error("Could not get access token response", t);
    }
    return null;
}
Also used : URLConnectionClient(org.apache.oltu.oauth2.client.URLConnectionClient) OAuthClient(org.apache.oltu.oauth2.client.OAuthClient) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Aggregations

OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)9 OAuthClient (org.apache.oltu.oauth2.client.OAuthClient)7 URLConnectionClient (org.apache.oltu.oauth2.client.URLConnectionClient)6 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)3 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)3 OAuthRegistrationClient (org.apache.oltu.oauth2.ext.dynamicreg.client.OAuthRegistrationClient)3 OAuthClientRegistrationResponse (org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse)3 URI (java.net.URI)2 Date (java.util.Date)2 OAuthBearerClientRequest (org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest)2 OAuthJSONAccessTokenResponse (org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse)2 OAuthResourceResponse (org.apache.oltu.oauth2.client.response.OAuthResourceResponse)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 SOAuthServer (org.bimserver.interfaces.objects.SOAuthServer)2 ServerException (org.bimserver.shared.exceptions.ServerException)2 UserException (org.bimserver.shared.exceptions.UserException)2 Before (org.junit.Before)2 RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)1 RemoteAPIToken (ca.corefacility.bioinformatics.irida.model.RemoteAPIToken)1 User (ca.corefacility.bioinformatics.irida.model.user.User)1