Getting error 405 'Method Not Allowed' when calling the 'certs' endpoint with HEAD method

closes #41537

Signed-off-by: mposolda <mposolda@gmail.com>
(cherry picked from commit 2dab73063dd5cc1fdcd5080f8a9f01222ea32d81)
This commit is contained in:
mposolda 2025-07-30 15:36:25 +02:00 committed by Marek Posolda
parent 699f61f168
commit 4699ea0662
3 changed files with 20 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package org.keycloak.protocol.oidc;
import jakarta.ws.rs.HEAD;
import org.jboss.resteasy.reactive.NoCache;
import org.keycloak.http.HttpRequest;
import org.keycloak.OAuthErrorException;
@ -195,6 +196,16 @@ public class OIDCLoginProtocolService {
return Cors.builder().allowedMethods("GET").preflight().auth().add(Response.ok());
}
// The method added just as a workaround to https://github.com/quarkusio/quarkus/issues/49172 . It can be removed once that one is
// fixed in quarkus and Keycloak updated to the corresponding version
@HEAD
@Path("/certs")
@Produces({MediaType.APPLICATION_JSON, org.keycloak.utils.MediaType.APPLICATION_JWKS})
@NoCache
public Response certsHead() {
return certs();
}
@GET
@Path("certs")
@Produces({MediaType.APPLICATION_JSON, org.keycloak.utils.MediaType.APPLICATION_JWKS})

View File

@ -49,4 +49,8 @@ public abstract class SimpleHttpDefault extends SimpleHttp {
return SimpleHttp.doGet(url, client, HttpClientProvider.DEFAULT_MAX_CONSUMED_RESPONSE_SIZE);
}
public static SimpleHttp doHead(String url, HttpClient client) {
return SimpleHttp.doHead(url, client, HttpClientProvider.DEFAULT_MAX_CONSUMED_RESPONSE_SIZE);
}
}

View File

@ -308,6 +308,11 @@ public abstract class AbstractWellKnownProviderTest extends AbstractKeycloakTest
SimpleHttp.Response response = SimpleHttpDefault.doGet(jwksUri, client).header(ACCEPT, APPLICATION_JWKS).asResponse();
assertEquals(APPLICATION_JWKS, response.getFirstHeader(CONTENT_TYPE));
// Test HEAD method works (Issue 41537)
SimpleHttp.Response responseHead = SimpleHttpDefault.doHead(jwksUri, client).header(ACCEPT, APPLICATION_JWKS).asResponse();
assertEquals(Response.Status.OK.getStatusCode(), responseHead.getStatus());
assertEquals(APPLICATION_JWKS, responseHead.getFirstHeader(CONTENT_TYPE));
}
@Test