Search in sources :

Example 1 with AuthorizationErrorResponse

use of com.nimbusds.oauth2.sdk.AuthorizationErrorResponse in project Kustvakt by KorAP.

the class OpenIdResponseHandler method createAuthorizationErrorResponse.

/**
 * According to OpenID connect core 1.0 specification, all
 * authentication errors must be represented through
 * AuthenticationErrorResponse. Moreover, for authorization code
 * flow, the error response parameters must be added to the
 * redirect URI as query parameters, unless a different response
 * mode was specified.
 *
 * {@link AuthorizationErrorResponse} defines specific
 * {@link ErrorObject}s regarding OAUTH2 errors.
 * {@link AuthenticationErrorResponse} defines additional
 * ErrorObjects regarding OpenID connect authenticaition errors.
 *
 * @param e
 *            a {@link KustvaktException}
 * @param isAuthentication
 * @param redirectURI
 * @param state
 * @param responseMode
 * @return a redirect uri with error response parameters as part
 *         of query parameters
 */
public Response createAuthorizationErrorResponse(KustvaktException e, boolean isAuthentication, URI redirectURI, State state, ResponseMode responseMode) {
    ErrorObject errorObject = createErrorObject(e);
    errorObject = errorObject.setDescription(e.getMessage());
    if (redirectURI == null) {
        return Response.status(errorObject.getHTTPStatusCode()).entity(errorObject.toJSONObject()).build();
    }
    URI uri = null;
    if (isAuthentication) {
        uri = new AuthenticationErrorResponse(redirectURI, errorObject, state, responseMode).toURI();
    } else {
        uri = new AuthorizationErrorResponse(redirectURI, errorObject, state, responseMode).toURI();
    }
    ResponseBuilder builder = Response.temporaryRedirect(uri).type(MediaType.APPLICATION_FORM_URLENCODED);
    return builder.build();
}
Also used : AuthorizationErrorResponse(com.nimbusds.oauth2.sdk.AuthorizationErrorResponse) AuthenticationErrorResponse(com.nimbusds.openid.connect.sdk.AuthenticationErrorResponse) ErrorObject(com.nimbusds.oauth2.sdk.ErrorObject) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI)

Example 2 with AuthorizationErrorResponse

use of com.nimbusds.oauth2.sdk.AuthorizationErrorResponse in project asgardeo-java-oidc-sdk by asgardeo.

the class DefaultOIDCManager method handleErrorAuthorizationResponse.

private void handleErrorAuthorizationResponse(AuthorizationResponse authorizationResponse) {
    AuthorizationErrorResponse errorResponse = authorizationResponse.toErrorResponse();
    JSONObject responseObject = errorResponse.getErrorObject().toJSONObject();
    logger.log(Level.INFO, "Error response object: " + responseObject);
}
Also used : AuthorizationErrorResponse(com.nimbusds.oauth2.sdk.AuthorizationErrorResponse) JSONObject(net.minidev.json.JSONObject)

Example 3 with AuthorizationErrorResponse

use of com.nimbusds.oauth2.sdk.AuthorizationErrorResponse in project asgardeo-java-oidc-sdk by asgardeo.

the class OIDCRequestResolver method logErrorAuthorizationResponse.

private void logErrorAuthorizationResponse(AuthorizationResponse authzResponse) {
    AuthorizationErrorResponse errorResponse = authzResponse.toErrorResponse();
    JSONObject responseObject = errorResponse.getErrorObject().toJSONObject();
    logger.log(Level.INFO, "Error response object: ", responseObject);
}
Also used : AuthorizationErrorResponse(com.nimbusds.oauth2.sdk.AuthorizationErrorResponse) JSONObject(net.minidev.json.JSONObject)

Aggregations

AuthorizationErrorResponse (com.nimbusds.oauth2.sdk.AuthorizationErrorResponse)3 JSONObject (net.minidev.json.JSONObject)2 ErrorObject (com.nimbusds.oauth2.sdk.ErrorObject)1 AuthenticationErrorResponse (com.nimbusds.openid.connect.sdk.AuthenticationErrorResponse)1 URI (java.net.URI)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1