All jobs

Add JWT Auth to a Quarkus API

Yes. An agent adds SmallRye JWT to a Quarkus REST API, keeps reads public and puts writes behind a role, mints test tokens, runs the Maven tests, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the resource it is protecting before it adds a dependency. In a service shaped like hibernate-orm-panache-quickstart inside quarkusio/quarkus-quickstarts, pom.xml sets quarkus.platform.version 3.40.1.1 with quarkus-hibernate-orm-panache, quarkus-rest-jackson, quarkus-jdbc-postgresql, quarkus-junit and rest-assured, Surefire 3.5.4 and the Failsafe plugin for @QuarkusIntegrationTest. FruitEntityResource at entity/fruits and FruitRepositoryResource at repository/fruits each expose GET list sorted by name, GET {id}, POST answering 201, PUT {id} and DELETE {id} answering 204, with a nested ErrorMapper that turns any exception into JSON with exceptionType, code and error. application.properties turns on SQL logging, loads import.sql, which seeds Cherry, Apple and Banana with ids 1 to 3 in both tables, and sets a %prod Postgres datasource at jdbc:postgresql://localhost/quarkus_test; dev and test set no URL, so Dev Services supply the database. FruitsEndpointTest is a @QuarkusTest that lists, deletes /1 and lists again on both paths, and FruitsEndpointIT extends it under @QuarkusIntegrationTest. Nothing is authenticated: anyone can delete every fruit.

The pattern comes from the same repository. security-jwt-quickstart uses quarkus-smallrye-jwt with mp.jwt.verify.publickey.location=publicKey.pem, mp.jwt.verify.issuer=https://example.com/issuer, a privateKey.pem under src/test/resources with smallrye.jwt.sign.key.location, and quarkus-smallrye-jwt-build to mint tokens as Jwt.issuer(...).upn(...).groups(...).sign() in its tests. The agent adds quarkus-smallrye-jwt to the fruit service's pom.xml and quarkus-smallrye-jwt-build in test scope, generates a fresh RSA key pair with openssl, commits the public key to src/main/resources and the private key to src/test/resources, and writes the three properties plus quarkus.native.resources.includes=publicKey.pem so a native build still finds the key. The issuer is a property, not a literal, so a deployment points it at its identity provider.

Then the annotations. Both resource classes get @PermitAll on the two GET methods and @RolesAllowed("admin") on POST, PUT and DELETE, so reads stay as they were and writes need a bearer token whose groups claim contains admin. With quarkus-smallrye-jwt on the classpath, Quarkus answers 401 for a missing or invalid token and 403 for a valid token without the role before the resource method runs, so the ErrorMapper never sees those cases and its JSON shape for 404 and 422 is untouched. The index.html under META-INF/resources that drives the list with fetch calls gets a note, not a login form; the pull request says that the page's create and delete buttons now need a token.

FruitsEndpointTest keeps performTest and gains three cases per path: DELETE /1 with no token answers 401, with a token whose groups are user answers 403, and with an admin token answers 204 and the list loses Cherry. Tokens are minted in the test with Jwt.issuer(...).groups(...).sign(), signed by the test key the %test profile names, the way TokenSecuredResourceTest does, and sent through RestAssured's given().auth().oauth2(token). FruitsEndpointIT inherits all of it. The run executes ./mvnw -pl hibernate-orm-panache-quickstart test from the repository root, where mvnw lives, and the verify goal for the integration test; both need a container runtime for the Dev Services Postgres, which the sandbox provides, or a %test.quarkus.datasource.jdbc.url pointing at a Postgres the agent starts itself.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "codex",
  "input": "Add JWT authentication to this Quarkus REST API and open a pull request. Read pom.xml, src/main/resources/application.properties, src/main/resources/import.sql, every class under src/main/java, FruitsEndpointTest and FruitsEndpointIT first. Add quarkus-smallrye-jwt and, in test scope, quarkus-smallrye-jwt-build. Generate an RSA key pair with openssl, put the public key in src/main/resources and the private key in src/test/resources, and set mp.jwt.verify.publickey.location, mp.jwt.verify.issuer as a property, smallrye.jwt.sign.key.location under the %test profile and quarkus.native.resources.includes. Annotate the GET methods of both resources with @PermitAll and POST, PUT and DELETE with @RolesAllowed(\"admin\"). Do not change the ErrorMapper or the response bodies. Extend FruitsEndpointTest so each path checks that DELETE without a token answers 401, with a user token answers 403, and with an admin token answers 204, minting tokens with Jwt.issuer().groups().sign() and sending them with RestAssured oauth2. Run the Maven test and verify goals for this module, with Dev Services or a Postgres you start, and paste the Surefire summary and one 401 response body in the pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that edits pom.xml, application.properties, both resource classes and FruitsEndpointTest, and adds publicKey.pem under src/main/resources and privateKey.pem under src/test/resources. The description shows the Surefire summary from the Maven run and a curl of DELETE /entity/fruits/1 without a token answering 401.

On a repository with the quickstarts' Pull Request Build workflow the pull request builds the module on JDK 21 with the cached Maven repository and runs its tests. The existing performTest still passes because the agent gives it an admin token for the delete step.

A reviewer checks that the private key is in src/test/resources only, that mp.jwt.verify.issuer is read from configuration rather than fixed to the test value, and that GET responses are byte-for-byte what they were. Then they set the issuer and public key for the environment that signs real tokens and merge.

Run it on every new Quarkus service

A team that runs several Quarkus services sends one POST /o/{org}/sessions per repository with this prompt and that repository in resources. Each run reads its own resources and tests, so a service that already uses quarkus-oidc gets @RolesAllowed on its write methods and no second extension, and each opens its own pull request with its own token tests.

Give the API key a webhook_url and Rush POSTs run.completed when each turn ends, with the session_url to read the pull request and the Surefire output from. Send a request_id with each start so a retry after a timeout returns the run already started.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Auth is the change whose failure mode is silence: a method left without an annotation stays open and no test notices. In a Rush sandbox the agent mints real tokens with the checked-in test key, sends them with RestAssured, and asserts 401, 403 and 204 on every write method, with the Maven output kept in the run's record, so the pull request shows each path closed rather than asserting it.

A Quarkus test run wants a JDK, a Maven cache and a container runtime for the Dev Services database, and the first build of the platform BOM is long. Each run on Rush does that in its own sandbox and parks when the turn ends, and the same request body works on every Quarkus service a team owns.

Frequently asked questions

Why SmallRye JWT and not OIDC?

The service has no identity provider in its configuration, and quarkus-smallrye-jwt verifies a bearer token against a public key with nothing else running. A service that signs in through Keycloak or another provider uses quarkus-oidc instead, and the agent does that if the prompt says so; the @RolesAllowed annotations are the same either way.

Is the private key safe to commit?

The private key lives in src/test/resources and signs test tokens only; the public key in src/main/resources is what production verifies. A deployment replaces the public key and the issuer with its own, and the pull request names both properties.

Does the ErrorMapper swallow the 401?

No. Authentication and authorization are decided before the resource method is invoked, so a 401 or 403 never reaches the mapper. The mapper keeps shaping the 404 for an unknown id and the 422 for a body with an id.

What about the HTML page in META-INF/resources?

It fetches the API directly and has no token, so its create and delete buttons stop working once writes are protected. The pull request leaves the page and notes the header it would need; a login flow for a static page is a separate change.

More Quarkus jobs

The same job on other stacks

Keep reading