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());
}
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);
}
}
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;
}
}
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;
}
}
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();
}
Aggregations