mirror of
https://github.com/ysoftdevs/oauth-playground-server.git
synced 2026-02-25 03:45:45 +01:00
DAG authorization pending - now correctly in JSON
This commit is contained in:
@@ -2,24 +2,37 @@ package com.ysoft.geecon.error;
|
||||
|
||||
import io.quarkus.qute.CheckedTemplate;
|
||||
import io.quarkus.qute.TemplateInstance;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.container.ResourceInfo;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ApplicationScoped
|
||||
class ExceptionMappers {
|
||||
@ServerExceptionMapper
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response mapJson(OAuthException exception) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(exception.getResponse()).build();
|
||||
}
|
||||
@Inject
|
||||
ResourceInfo resourceInfo;
|
||||
|
||||
@ServerExceptionMapper
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response mapHtml(OAuthException exception) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(Templates.error(exception.getResponse())).build();
|
||||
public Response exception(OAuthException exception) {
|
||||
Object entity = producesJson() ? exception.getResponse() : Templates.error(exception.getResponse());
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(entity).build();
|
||||
}
|
||||
|
||||
private boolean producesJson() {
|
||||
Produces annotation = resourceInfo.getResourceMethod().getAnnotation(Produces.class);
|
||||
if (annotation == null) {
|
||||
return false;
|
||||
}
|
||||
String[] produces = annotation.value();
|
||||
return Arrays.asList(produces).contains(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
|
||||
@CheckedTemplate
|
||||
public static class Templates {
|
||||
public static native TemplateInstance error(OAuthException.ErrorResponse response);
|
||||
|
||||
@@ -71,6 +71,6 @@ public class DeviceAuthGrantTest {
|
||||
public void deviceAuthGrant_authorizationPending() throws IOException {
|
||||
DeviceAuthorizationGrantFlow flow = new DeviceAuthorizationGrantFlow(deviceUri, CLIENT);
|
||||
flow.start();
|
||||
System.err.println(flow.exchangeDeviceCodeError());
|
||||
flow.exchangeDeviceCodeError();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.ysoft.geecon.helpers;
|
||||
import com.ysoft.geecon.dto.AccessTokenResponse;
|
||||
import com.ysoft.geecon.dto.DeviceResponse;
|
||||
import com.ysoft.geecon.dto.OAuthClient;
|
||||
import com.ysoft.geecon.error.OAuthException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -55,7 +56,7 @@ public class DeviceAuthorizationGrantFlow {
|
||||
.extract().as(AccessTokenResponse.class);
|
||||
}
|
||||
|
||||
public String exchangeDeviceCodeError() {
|
||||
public OAuthException.ErrorResponse exchangeDeviceCodeError() {
|
||||
return given()
|
||||
.formParam("grant_type", "urn:ietf:params:oauth:grant-type:device_code")
|
||||
.formParam("client_id", client.clientId())
|
||||
@@ -63,10 +64,10 @@ public class DeviceAuthorizationGrantFlow {
|
||||
.when()
|
||||
.post("/auth/token")
|
||||
.then()
|
||||
.statusCode(400).extract().asString();
|
||||
// .contentType(JSON)
|
||||
// .body("error", is(notNullValue()))
|
||||
// .body("error_detail", is(notNullValue()))
|
||||
// .extract().as(OAuthException.ErrorResponse.class);
|
||||
.statusCode(400)
|
||||
.contentType(JSON)
|
||||
.body("error", is(notNullValue()))
|
||||
.body("error_description", is(notNullValue()))
|
||||
.extract().as(OAuthException.ErrorResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user