Search in sources :

Example 1 with AuthorizationCodeGrant

use of org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant in project cxf by apache.

the class ClientCodeRequestFilter method prepareCodeGrant.

private AuthorizationCodeGrant prepareCodeGrant(String codeParam, URI absoluteRedirectUri) {
    if (codeRequestJoseProducer == null) {
        return new AuthorizationCodeGrant(codeParam, absoluteRedirectUri);
    }
    JwtRequestCodeGrant grant = new JwtRequestCodeGrant(codeParam, absoluteRedirectUri, consumer.getClientId());
    grant.setClientSecret(consumer.getClientSecret());
    grant.setJoseProducer(codeRequestJoseProducer);
    return grant;
}
Also used : JwtRequestCodeGrant(org.apache.cxf.rs.security.oauth2.grants.code.JwtRequestCodeGrant) AuthorizationCodeGrant(org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant)

Example 2 with AuthorizationCodeGrant

use of org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant in project cxf by apache.

the class CodeAuthSupplier method getAuthorization.

public String getAuthorization(AuthorizationPolicy authPolicy, URI currentURI, Message message, String fullHeader) {
    if (code != null) {
        synchronized (tokenSupplier) {
            if (tokenSupplier.getClientAccessToken().getTokenKey() == null) {
                WebClient wc = tokenSupplier.createAccessTokenServiceClient();
                ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, tokenSupplier.getConsumer(), new AuthorizationCodeGrant(code));
                code = null;
                tokenSupplier.setClientAccessToken(at);
            }
        }
    }
    return tokenSupplier.getAuthorization(authPolicy, currentURI, message, fullHeader);
}
Also used : AuthorizationCodeGrant(org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 3 with AuthorizationCodeGrant

use of org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant in project cxf by apache.

the class ClientCodeRequestFilter method processCodeResponse.

protected void processCodeResponse(ContainerRequestContext rc, UriInfo ui, MultivaluedMap<String, String> requestParams) {
    MultivaluedMap<String, String> state = null;
    if (clientStateManager != null) {
        state = clientStateManager.fromRedirectState(mc, requestParams);
    }
    String codeParam = requestParams.getFirst(OAuthConstants.AUTHORIZATION_CODE_VALUE);
    ClientAccessToken at = null;
    if (codeParam != null) {
        AuthorizationCodeGrant grant = prepareCodeGrant(codeParam, getAbsoluteRedirectUri(ui));
        if (state != null) {
            grant.setCodeVerifier(state.getFirst(OAuthConstants.AUTHORIZATION_CODE_VERIFIER));
        }
        at = OAuthClientUtils.getAccessToken(accessTokenServiceClient, consumer, grant, useAuthorizationHeader);
    }
    ClientTokenContext tokenContext = initializeClientTokenContext(rc, at, requestParams, state);
    if (at != null && clientTokenContextManager != null) {
        clientTokenContextManager.setClientTokenContext(mc, tokenContext);
    }
    setClientCodeRequest(tokenContext);
}
Also used : AuthorizationCodeGrant(org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)

Aggregations

AuthorizationCodeGrant (org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant)3 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 JwtRequestCodeGrant (org.apache.cxf.rs.security.oauth2.grants.code.JwtRequestCodeGrant)1