Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

JAX-RS OIDC Login: Configure pac4j Callbacks and Protected Routes

A practical pac4j guide for JAX-RS developers: configure OIDC browser login or bearer-token authentication, wire runtime features, and avoid demo-only security settings.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To add interactive OpenID Connect login to a JAX-RS application with pac4j, configure an OidcClient, register the runtime-specific pac4j features and profile injector, expose callback and logout endpoints, and protect resources with @Pac4JSecurity. The provider must allow the exact callback URL, including ?client_name=OidcClient. If callers already send bearer tokens, use pac4j’s separate direct-client pattern instead; it does not use the browser redirect and session flow.

Choose the authentication flow and JAX-RS runtime

First decide whether users sign in through a browser or an API caller presents an access token. Those are different integrations: browser login redirects to an identity provider and needs state preserved across the redirect, while the bearer-token pattern validates an existing token without redirecting the caller.

As an Amazon Associate I earn from qualifying purchases.

Use case pac4j approach What the application needs
Interactive browser login Indirect OIDC client, typically OidcClient Provider redirect, callback and logout resources, and session support for state
API request with an existing token HeaderClient using the OIDC profile creator An Authorization: Bearer ... header; no browser redirect or local session

Use the integration module that matches the JAX-RS runtime line: the guide lists jersey3-pac4j, jersey4-pac4j, resteasy6-pac4j, and resteasy7-pac4j. Runtime-specific request/session access and profile injection are not interchangeable. Dropwizard’s pac4j bundle handles much of the feature registration for its integration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set up OIDC browser login

Check prerequisites and dependencies

The official pac4j guide’s standalone example uses Java 17 or later and Maven, with Jersey 4 and Grizzly. Its example versions are jersey4-pac4j 8.0.0 and pac4j-oidc 6.5.8; these are example coordinates, not a guarantee that every combination of pac4j and runtime versions is compatible. Check the project’s dependency and release documentation before selecting versions. The guide’s implementation steps are at pac4j’s OIDC client documentation.

#1 Best Overall

Register an OIDC application with your identity provider and obtain its client ID and secret. Configure the provider’s discovery URI, usually its .well-known/openid-configuration endpoint. pac4j reads the provider metadata to locate endpoints such as authorization, token, user-info, and JWKS.

Configure the client and callback URL

Create an OidcConfiguration with the discovery URI, client ID, and client secret, then construct an OidcClient. Pass the callback base URL when creating pac4j’s Config, for example:

OidcConfiguration oidcConfiguration = new OidcConfiguration();
oidcConfiguration.setDiscoveryURI(discoveryUri);
oidcConfiguration.setClientId(clientId);
oidcConfiguration.setSecret(clientSecret);

OidcClient oidcClient = new OidcClient(oidcConfiguration);
Config config = new Config(baseUrl + "/callback", oidcClient);

Register the externally reachable callback URI with the identity provider, including pac4j’s client-name query parameter. For the generic client, the form is https://your-public-host/your-context/callback?client_name=OidcClient. Match the actual public scheme, hostname, port, context path, callback path, and query string exactly. If a reverse proxy exposes a different public URL from the application’s internal address, use the public URL in the provider registration and pac4j configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Register the runtime features

For the guide’s standalone Jersey 4 and Grizzly example, register Pac4JGrizzlyFeature to provide request and session access, Pac4JSecurityFeature for pac4j security, and Pac4JValueFactoryProvider.Binder for profile injection. In a servlet deployment, register Pac4JServletFeature(config) to use the container’s HttpSession. RESTEasy with CDI uses its security feature and Pac4JProfileInjectorFactory rather than Jersey’s value-factory binder. Use the setup for your actual runtime, not a mixture of registration examples.

Add callback, logout, and protected resources

Provide resource methods annotated with @Pac4JCallback and @Pac4JLogout so pac4j can complete the OIDC callback and handle logout. Protect the resource or class that requires authentication with @Pac4JSecurity(clients = "OidcClient"). Inject the authenticated profile with @Pac4JProfile; if injection is missing, confirm that the runtime-specific injector or value factory is registered.

Handle bearer-token API requests separately

For an API that receives an access token in the request, the guide uses pac4j-http and a HeaderClient configured to read the Authorization: Bearer header. Initialize the OIDC client and use its profile creator to validate the token through the provider’s user-info endpoint. In this mode the example sets the OIDC callback URL to notused and uses a no-op session store; it does not send the caller through a login redirect or depend on browser session state.

A rejected token can result in an unauthorized response. Check that the token comes from the expected issuer/provider and that the request meets the provider’s requirements, including the openid scope described in the pac4j OIDC guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Adapt provider and client names consistently

The generic OidcClient uses discovery metadata. pac4j also documents provider-specific clients for common identity providers. The guide includes examples for Keycloak, Google, and Microsoft Entra ID, and describes generic OIDC use with providers such as Okta, Auth0, and CAS. Provider selection can change the discovery configuration and, for a provider-specific client, the client class or name. Keep the chosen client name consistent in the callback URI’s client_name parameter and the @Pac4JSecurity annotation. Provider console labels and endpoints may change, so use the provider’s current OIDC application instructions.

Remove demo-only security settings before deployment

The public guide’s demo allows unsigned ID tokens with setAllowUnsignedIdTokens(true). Do not carry that setting into a real-provider deployment: remove it so signature verification can use the provider’s JWKS. Also review session renewal for the runtime you deploy. The Grizzly example sets renewSession = false and warns about session identifier rotation and session fixation; the guide recommends a servlet-backed runtime with renewSession = true, or validating renewal behavior against the Grizzly version before enabling it.

Troubleshoot common integration failures

  • “Invalid redirect URI”: Compare the provider’s registered URI with the externally reachable callback, including context path and ?client_name=OidcClient.
  • Login repeats or loses state: Confirm that the browser-login deployment registers the appropriate Grizzly or servlet session feature.
  • @Pac4JProfile is not populated: Register the profile injector for the actual runtime; Jersey and RESTEasy use different setup.
  • Bearer-token request returns 401: Check token issuer/provider acceptance and required scopes, including openid; this flow validates the supplied token rather than logging a user in interactively.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.