Handling Dynamic Redirect URLs for Multi-Tenant SaaS with OAuth in Quarkus #47194
-
Hello everyone, I'm building a multi-tenant SaaS application using Quarkus and implementing OAuth 2.0 for authentication. Our tenant URLs follow a pattern like http://localhost:9000/store/{tenantId}/dashboard, where {tenantId} is a unique identifier for each tenant (e.g., 314249607888530860). The challenge I'm facing is how to handle the redirect_uri parameter during the OAuth flow. Since OAuth providers generally discourage or don't allow wildcard redirect URLs for security reasons, I need a way to ensure users are redirected back to the correct tenant-specific URL and their intended destination after successful authentication. Currently, I have a custom TenantConfigResolver that dynamically determines the OIDC tenant configuration based on the incoming request path. Here's my implementation:
My current approach for the callback handler looks like this: Java
My current strategy involves setting a generic callback URL (/auth/callback/store) in the tenant configuration and then attempting to retrieve the original requested URL from the session in the callback handler. However, I'm not seeing the original URL being available in the session within the CallbackResource. My questions are:
Any insights or best practices would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
@uhexos Hi, you can use Or, in your callback resource, you can inject You don't need to try to get the state cookie content. Also, the callback handler should have |
Beta Was this translation helpful? Give feedback.
@uhexos Hi, you can use
quarkus.oidc.authentication.restore-path-after-redirect
and the user will be redirected to the original path.Or, in your callback resource, you can inject
OidcSession
, get the tenant id, and redirect the user further.You don't need to try to get the state cookie content.
Also, the callback handler should have
@Authenticated
, by the time it is called , the authorization code flow already completed