Search in sources :

Example 1 with LogoutRequest

use of com.nimbusds.openid.connect.sdk.LogoutRequest in project pac4j by pac4j.

the class OidcLogoutActionBuilder method getLogoutAction.

@Override
public RedirectAction getLogoutAction(final WebContext context, final U currentProfile, final String targetUrl) {
    final String logoutUrl = configuration.getLogoutUrl();
    if (CommonHelper.isNotBlank(logoutUrl)) {
        try {
            final URI endSessionEndpoint = new URI(logoutUrl);
            final JWT idToken = currentProfile.getIdToken();
            LogoutRequest logoutRequest;
            if (CommonHelper.isNotBlank(targetUrl)) {
                logoutRequest = new LogoutRequest(endSessionEndpoint, idToken, new URI(targetUrl), null);
            } else {
                logoutRequest = new LogoutRequest(endSessionEndpoint, idToken);
            }
            if (ajaxRequestResolver.isAjax(context)) {
                context.getSessionStore().set(context, Pac4jConstants.REQUESTED_URL, "");
                context.setResponseHeader(HttpConstants.LOCATION_HEADER, logoutRequest.toURI().toString());
                throw HttpAction.status(403, context);
            }
            return RedirectAction.redirect(logoutRequest.toURI().toString());
        } catch (final URISyntaxException e) {
            throw new TechnicalException(e);
        }
    }
    return null;
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) JWT(com.nimbusds.jwt.JWT) LogoutRequest(com.nimbusds.openid.connect.sdk.LogoutRequest) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

JWT (com.nimbusds.jwt.JWT)1 LogoutRequest (com.nimbusds.openid.connect.sdk.LogoutRequest)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 TechnicalException (org.pac4j.core.exception.TechnicalException)1