OIDC with KeyCloak multi-tenant setup. #52844
-
|
I am trying to configure my application with OIDC. In our setup, each tenant in KeyCloak is configured in their own realm. What might I be doing wrong? How should I go about doing this? My end-goal is to allow the OAuth2 authentication to work & validate JWT tokens using OIDC - provided the issuer base URL matches our KeyCloak instance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
/cc @sberyozkin (keycloak,oidc) |
Beta Was this translation helpful? Give feedback.
-
|
Quarkus OIDC has built-in multi-tenant support. The key is implementing a Here's the pattern: @ApplicationScoped
public class CustomTenantConfigResolver implements TenantConfigResolver {
@Override
public Uni<OidcTenantConfig> resolve(RoutingContext context, OidcRequestContext<OidcTenantConfig> requestContext) {
String tenantId = extractTenantId(context); // from path, header, or subdomain
OidcTenantConfig config = new OidcTenantConfig();
config.setTenantId(tenantId);
config.setAuthServerUrl("https://keycloak.example.com/realms/" + tenantId);
config.setClientId("my-app");
config.setApplicationType(OidcTenantConfig.ApplicationType.SERVICE);
return Uni.createFrom().item(config);
}
private String extractTenantId(RoutingContext context) {
// Option 1: From path parameter
// e.g., /api/{tenant}/resource
return context.pathParam("tenant");
// Option 2: From header
// return context.request().getHeader("X-Tenant-ID");
}
}Important notes:
See the Quarkus OIDC Multi-Tenancy guide for the full documentation. |
Beta Was this translation helpful? Give feedback.
@mustafamotiwala Sure,
quarkus.oidc.tenant-enabled=falsewould be fine, please try.Users should not be required to do
quarkus.oidc.tenant-enabled=falsethough when a resolver is available, let me check