Search in sources :

Example 1 with UriBuilder

use of io.gravitee.am.common.web.UriBuilder in project gravitee-access-management by gravitee-io.

the class IdentifierFirstLoginEndpoint method doExternalRedirect.

private void doExternalRedirect(RoutingContext routingContext, IdentityProvider identityProvider) {
    Map<String, String> urls = routingContext.get(SOCIAL_AUTHORIZE_URL_CONTEXT_KEY);
    UriBuilder uriBuilder = UriBuilder.fromHttpUrl(urls.get(identityProvider.getId()));
    // encode login_hint parameter for external provider (Azure AD replace the '+' sign by a space ' ')
    uriBuilder.addParameter(Parameters.LOGIN_HINT, UriBuilder.encodeURIComponent(routingContext.request().getParam(USERNAME_PARAM_KEY)));
    doRedirect0(routingContext, uriBuilder.buildString());
}
Also used : UriBuilder(io.gravitee.am.common.web.UriBuilder)

Example 2 with UriBuilder

use of io.gravitee.am.common.web.UriBuilder in project gravitee-access-management by gravitee-io.

the class AbstractLogoutEndpoint method doRedirect0.

private void doRedirect0(RoutingContext routingContext, String url) {
    // state OPTIONAL. Opaque value used by the RP to maintain state between the logout request and the callback to the endpoint specified by the post_logout_redirect_uri parameter.
    // If included in the logout request, the OP passes this value back to the RP using the state parameter when redirecting the User Agent back to the RP.
    UriBuilder uriBuilder = UriBuilder.fromURIString(url);
    final String state = routingContext.request().getParam(io.gravitee.am.common.oauth2.Parameters.STATE);
    if (!StringUtils.isEmpty(state)) {
        uriBuilder.addParameter(io.gravitee.am.common.oauth2.Parameters.STATE, state);
    }
    try {
        routingContext.response().putHeader(HttpHeaders.LOCATION, uriBuilder.buildString()).setStatusCode(302).end();
    } catch (Exception ex) {
        LOGGER.error("An error has occurred during post-logout redirection", ex);
        routingContext.fail(500);
    }
}
Also used : UriBuilder(io.gravitee.am.common.web.UriBuilder) InvalidRequestException(io.gravitee.am.common.exception.oauth2.InvalidRequestException)

Example 3 with UriBuilder

use of io.gravitee.am.common.web.UriBuilder in project gravitee-access-management by gravitee-io.

the class AbstractOpenIDConnectAuthenticationProvider method signInUrl.

@Override
public Request signInUrl(String redirectUri, String state) {
    try {
        if (getConfiguration().getUserAuthorizationUri() == null) {
            LOGGER.warn("Social Provider {} can't provide signInUrl, userAuthorizationUri is null", this.getClass().getSimpleName());
            return null;
        }
        UriBuilder builder = UriBuilder.fromHttpUrl(getConfiguration().getUserAuthorizationUri());
        builder.addParameter(Parameters.CLIENT_ID, getConfiguration().getClientId());
        builder.addParameter(Parameters.RESPONSE_TYPE, getConfiguration().getResponseType());
        // append scopes
        if (getConfiguration().getScopes() != null && !getConfiguration().getScopes().isEmpty()) {
            builder.addParameter(Parameters.SCOPE, String.join(SCOPE_DELIMITER, getConfiguration().getScopes()));
        }
        // nonce parameter is required for implicit/hybrid flow
        if (!io.gravitee.am.common.oauth2.ResponseType.CODE.equals(getConfiguration().getResponseType())) {
            builder.addParameter(io.gravitee.am.common.oidc.Parameters.NONCE, SecureRandomString.generate());
        }
        // add state if provided.
        if (!StringUtils.isEmpty(state)) {
            builder.addParameter(Parameters.STATE, state);
        }
        // append redirect_uri
        builder.addParameter(Parameters.REDIRECT_URI, getConfiguration().isEncodeRedirectUri() ? encodeURIComponent(redirectUri) : redirectUri);
        Request request = new Request();
        request.setMethod(HttpMethod.GET);
        request.setUri(builder.buildString());
        return request;
    } catch (Exception e) {
        LOGGER.error("An error has occurred while building OpenID Connect Sign In URL", e);
        return null;
    }
}
Also used : HttpRequest(io.vertx.reactivex.ext.web.client.HttpRequest) Request(io.gravitee.am.identityprovider.api.common.Request) UriBuilder(io.gravitee.am.common.web.UriBuilder) InternalAuthenticationServiceException(io.gravitee.am.common.exception.authentication.InternalAuthenticationServiceException) BadCredentialsException(io.gravitee.am.common.exception.authentication.BadCredentialsException)

Example 4 with UriBuilder

use of io.gravitee.am.common.web.UriBuilder in project gravitee-access-management by gravitee-io.

the class AbstractSocialAuthenticationProvider method signInUrl.

@Override
public Request signInUrl(String redirectUri, String state) {
    try {
        UriBuilder builder = UriBuilder.fromHttpUrl(getConfiguration().getUserAuthorizationUri());
        builder.addParameter(Parameters.CLIENT_ID, getConfiguration().getClientId());
        builder.addParameter(Parameters.REDIRECT_URI, redirectUri);
        builder.addParameter(Parameters.RESPONSE_TYPE, getConfiguration().getResponseType());
        if (getConfiguration().getScopes() != null && !getConfiguration().getScopes().isEmpty()) {
            builder.addParameter(Parameters.SCOPE, String.join(SCOPE_DELIMITER, getConfiguration().getScopes()));
        }
        if (!StringUtils.isEmpty(state)) {
            builder.addParameter(Parameters.STATE, state);
        }
        Request request = new Request();
        request.setMethod(HttpMethod.GET);
        request.setUri(builder.build().toString());
        return request;
    } catch (Exception e) {
        LOGGER.error("An error occurs while building Sign In URL", e);
        return null;
    }
}
Also used : Request(io.gravitee.am.identityprovider.api.common.Request) UriBuilder(io.gravitee.am.common.web.UriBuilder)

Example 5 with UriBuilder

use of io.gravitee.am.common.web.UriBuilder in project gravitee-access-management by gravitee-io.

the class AuthorizationCodeResponse method buildRedirectUri.

@Override
public String buildRedirectUri() throws URISyntaxException {
    UriBuilder uriBuilder = UriBuilder.fromURIString(getRedirectUri());
    uriBuilder.addParameter(Parameters.CODE, getCode());
    if (getState() != null) {
        uriBuilder.addParameter(Parameters.STATE, getState());
    }
    return uriBuilder.buildString();
}
Also used : UriBuilder(io.gravitee.am.common.web.UriBuilder)

Aggregations

UriBuilder (io.gravitee.am.common.web.UriBuilder)13 Request (io.gravitee.am.identityprovider.api.common.Request)5 BadCredentialsException (io.gravitee.am.common.exception.authentication.BadCredentialsException)3 Token (io.gravitee.am.gateway.handler.oauth2.service.token.Token)2 InternalAuthenticationServiceException (io.gravitee.am.common.exception.authentication.InternalAuthenticationServiceException)1 InvalidRequestException (io.gravitee.am.common.exception.oauth2.InvalidRequestException)1 JWT (io.gravitee.am.common.jwt.JWT)1 Parameters (io.gravitee.am.common.oidc.Parameters)1 ConstantKeys (io.gravitee.am.common.utils.ConstantKeys)1 IdentityProviderManager (io.gravitee.am.gateway.handler.common.auth.idp.IdentityProviderManager)1 EndUserAuthentication (io.gravitee.am.gateway.handler.common.auth.user.EndUserAuthentication)1 CertificateManager (io.gravitee.am.gateway.handler.common.certificate.CertificateManager)1 ClientSyncService (io.gravitee.am.gateway.handler.common.client.ClientSyncService)1 JWTService (io.gravitee.am.gateway.handler.common.jwt.JWTService)1 VertxHttpServerRequest (io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest)1 RequestUtils (io.gravitee.am.gateway.handler.common.vertx.utils.RequestUtils)1 UriBuilderRequest (io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest)1 CONTEXT_PATH (io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest.CONTEXT_PATH)1 UserService (io.gravitee.am.gateway.handler.root.service.user.UserService)1 UserToken (io.gravitee.am.gateway.handler.root.service.user.model.UserToken)1