use of io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest.CONTEXT_PATH in project gravitee-access-management by gravitee-io.
the class LogoutEndpoint method generateLogoutCallback.
private Maybe<String> generateLogoutCallback(RoutingContext routingContext, User endUser, Request endpoint) {
// Single Logout can be done only if the endUser profile contains an IdToken.
if (endUser.getAdditionalInformation() == null) {
return Maybe.empty();
}
if (!endUser.getAdditionalInformation().containsKey(ConstantKeys.OIDC_PROVIDER_ID_TOKEN_KEY)) {
return Maybe.empty();
}
// Generate a state containing provider id and current query parameter string.
// This state will be sent back to AM after social logout.
final String delegatedOpIdToken = (String) endUser.getAdditionalInformation().get(ConstantKeys.OIDC_PROVIDER_ID_TOKEN_KEY);
final JWT stateJwt = new JWT();
stateJwt.put("c", endUser.getClient());
stateJwt.put("p", endUser.getSource());
stateJwt.put("q", routingContext.request().query());
// remove state from the request to avoid duplicate state parameter into the external idp logout request
// this state will be restored after the redirect triggered by the external idp
routingContext.request().params().remove(io.gravitee.am.common.oauth2.Parameters.STATE);
return jwtService.encode(stateJwt, certificateManager.defaultCertificateProvider()).map(state -> {
String redirectUri = UriBuilderRequest.resolveProxyRequest(routingContext.request(), routingContext.get(CONTEXT_PATH) + "/logout/callback");
UriBuilder builder = UriBuilder.fromHttpUrl(endpoint.getUri());
builder.addParameter(Parameters.POST_LOGOUT_REDIRECT_URI, redirectUri);
builder.addParameter(Parameters.ID_TOKEN_HINT, delegatedOpIdToken);
builder.addParameter(io.gravitee.am.common.oauth2.Parameters.STATE, state);
return builder.buildString();
}).toMaybe();
}
Aggregations