@@ -414,6 +414,7 @@ public final class OidcConfig extends TenantConfigImpl {
414414 private final boolean pkceEnabled ;
415415 private final PkceChallengeMethod pkceChallengeMethod ;
416416 private final OidcOutboundType outboundType ;
417+ private final ClientCredentialsConfig clientCredentialsConfig ;
417418
418419 private OidcConfig (Builder builder ) {
419420 super (builder );
@@ -453,6 +454,7 @@ private OidcConfig(Builder builder) {
453454 this .webClientBuilderSupplier = builder .webClientBuilderSupplier ;
454455 this .defaultTenant = LazyValue .create (() -> Tenant .create (this , this ));
455456 this .outboundType = builder .outboundType ;
457+ this .clientCredentialsConfig = builder .clientCredentialsConfig ;
456458
457459 LOGGER .log (Level .TRACE , () -> "Redirect URI with host: " + frontendUri + redirectUri );
458460 }
@@ -871,6 +873,15 @@ public OidcOutboundType outboundType() {
871873 return outboundType ;
872874 }
873875
876+ /**
877+ * Client credentials configuration.
878+ *
879+ * @return client credentials config
880+ */
881+ public ClientCredentialsConfig clientCredentialsConfig () {
882+ return clientCredentialsConfig ;
883+ }
884+
874885 Supplier <WebClientConfig .Builder > webClientBuilderSupplier () {
875886 return webClientBuilderSupplier ;
876887 }
@@ -988,6 +999,7 @@ public static class Builder extends BaseBuilder<Builder, OidcConfig> {
988999 private boolean useHeader = DEFAULT_HEADER_USE ;
9891000 private boolean useParam = DEFAULT_PARAM_USE ;
9901001 private OidcOutboundType outboundType = OidcOutboundType .USER_JWT ;
1002+ private ClientCredentialsConfig clientCredentialsConfig = ClientCredentialsConfig .create ();
9911003 private boolean pkceEnabled = DEFAULT_PKCE_ENABLED ;
9921004 private PkceChallengeMethod pkceChallengeMethod = PkceChallengeMethod .S256 ;
9931005
@@ -1037,6 +1049,13 @@ public OidcConfig build() {
10371049 collector .fatal ("post-logout-uri must be defined when logout is enabled." );
10381050 }
10391051 }
1052+ if (outboundType == OidcOutboundType .CLIENT_CREDENTIALS ) {
1053+ if (clientCredentialsConfig .scope ().isEmpty ()
1054+ && serverType ().equals ("idcs" )) {
1055+ collector .fatal ("client-credential.scope must be defined when client credentials flow "
1056+ + "is set as an outbound type and \" idcs\" is the server type" );
1057+ }
1058+ }
10401059
10411060 // second set of validations
10421061 collector .collect ().checkValid ();
@@ -1172,6 +1191,8 @@ public Builder config(Config config) {
11721191 .ifPresent (confList -> confList .forEach (tenantConfig -> tenantFromConfig (config , tenantConfig )));
11731192
11741193 config .get ("outbound-type" ).as (OidcOutboundType .class ).ifPresent (this ::outboundType );
1194+ config .get ("client-credentials" ).as (Config .class )
1195+ .ifPresent (it -> clientCredentialsConfig (ClientCredentialsConfig .create (it )));
11751196 config .get ("pkce-enabled" ).asBoolean ().ifPresent (this ::pkceEnabled );
11761197 config .get ("pkce-challenge-method" ).as (PkceChallengeMethod .class ).ifPresent (this ::pkceChallengeMethod );
11771198
@@ -1906,5 +1927,31 @@ public Builder clientTimeout(Duration duration) {
19061927 webClientConfigBuilder .socketOptions (newSocketBuilder );
19071928 return this ;
19081929 }
1930+
1931+ /**
1932+ * Set the configuration related to the client credentials flow.
1933+ *
1934+ * @param clientCredentialsConfig client credentials configuration
1935+ * @return updated builder instance
1936+ */
1937+ @ ConfiguredOption
1938+ public Builder clientCredentialsConfig (ClientCredentialsConfig clientCredentialsConfig ) {
1939+ this .clientCredentialsConfig = Objects .requireNonNull (clientCredentialsConfig );
1940+ return this ;
1941+ }
1942+
1943+ /**
1944+ * Configure client credentials configuration over the builder consumer.
1945+ *
1946+ * @param builderConsumer builder consumer
1947+ * @return updated builder instance
1948+ */
1949+ public Builder clientCredentialsConfig (Consumer <ClientCredentialsConfig .Builder > builderConsumer ) {
1950+ var builder = ClientCredentialsConfig .builder ();
1951+ builderConsumer .accept (builder );
1952+ this .clientCredentialsConfig = builder .build ();
1953+ return this ;
1954+ }
1955+
19091956 }
19101957}
0 commit comments