0

I am using quarkus in a new project and on o GET request I want to get the bearer token from the request.

while I am testing the request with postman (or talent api) it work perfect and retrieves the response data, but with I am trying to add authorization headers on request the request does not work. not even stops on break point and the response as 401 Unauthorized.

@GET
@Path("/all")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
@Operation(summary = "Retrieves all mailbox ", description = "Retrieves all mailbox using search ")
public Response getAllMailbox(@DefaultValue("0") @QueryParam("page") int page,
                              @DefaultValue("20") @QueryParam("max") int max,
                              @DefaultValue("mail.receivedate") @QueryParam("orderby") String orderby,
                              @DefaultValue("") @QueryParam("search") String search) {
    MailboxResponse mailboxResponse;
    try {
        mailboxResponse = mailboxManager.getAllMailbox(search, page, max, orderby, asc, headers);
    } catch (Exception e) {
        return Response.serverError().build();
    }
    return Response.status(Response.Status.OK).entity(mailboxResponse).build();
}

in previous version using java ee with jaxs-rs I was using annotation

    @Context HttpHeaders headers;

and so I had access on token on request.

any idea how I can do the same thing on quarkus?

stg
  • 62
  • 2
  • 10
  • Do you use `quarkus-oidc` or `quarkus-smallrye-jwt` ? If you do then even if you send a token to the public endpoint, it will be verified and the request will fail if the token is invalid. So if you'd like to access the public endpoint while sending a possibly invalid token, then you should disable the proactive authentication: `quarkus.http.auth.proactive=false`. Can you try it ? – Sergey Beryozkin Feb 23 '23 at 10:49
  • Thanks your answer, I am using quarkus-smallrye-jwt and it continues not to work.. another solution I found is by adding group role that are allowed for the request on the token creation and then by using @RolesAllowed({ "Administrator", "All" }) it works.. this is something that as ok for me at that moment.. – stg Feb 24 '23 at 09:49
  • If you can create a reproducer then I can have a deeper look as I'm not sure I understand what is actually going on, but glad you've managed to have it working in any case – Sergey Beryozkin Feb 26 '23 at 21:47

0 Answers0