3.6. Programmatic OIDC start-up
OIDC tenants can be created programmatically like in the example below:
package io.quarkus.it.oidc;
import io.quarkus.oidc.Oidc;
import jakarta.enterprise.event.Observes;
public class OidcStartup {
void observe(@Observes Oidc oidc) {
oidc.createWebApp("http://localhost:8180/realms/quarkus", "quarkus-app", "mysecret");
}
}
The code above is a programmatic equivalent to the following configuration in the application.properties file:
quarkus.oidc.auth-server-url=http://localhost:8180/realms/quarkus
quarkus.oidc.application-type=web-app
quarkus.oidc.client-id=quarkus-app
quarkus.oidc.credentials.secret=mysecret
Should you need to configure more OIDC tenant properties, use the OidcTenantConfig builder like in the example below:
package io.quarkus.it.oidc;
import io.quarkus.oidc.Oidc;
import io.quarkus.oidc.OidcTenantConfig;
import io.quarkus.oidc.common.runtime.config.OidcClientCommonConfig.Credentials.Secret.Method;
import jakarta.enterprise.event.Observes;
public class OidcStartup {
void createDefaultTenant(@Observes Oidc oidc) {
var defaultTenant = OidcTenantConfig
.authServerUrl("http://localhost:8180/realms/quarkus/")
.clientId("quarkus-app")
.credentials().clientSecret("mysecret", Method.POST).end()
.build();
oidc.create(defaultTenant);
}
}
For more complex setup involving multiple tenants please see the Programmatic OIDC start-up for multitenant application section of the OpenID Connect Multi-Tenancy guide.