diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/ServiceFactory.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/ServiceFactory.java index 5d9d69e76..b38811ad3 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/ServiceFactory.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/ServiceFactory.java @@ -93,8 +93,18 @@ public ServiceFactory(ApiClientFactory apiClientFactory, AuthSession authSession + " please set commonJwt.enabled to false."); } else { final OAuthSession oAuthSession = new OAuthSession(authSession); + this.podClient.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken)); this.podClient.addEnforcedAuthenticationScheme(BEARER_AUTH); + + this.agentClient.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken)); + this.agentClient.addEnforcedAuthenticationScheme(BEARER_AUTH); + + this.datafeedAgentClient.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken)); + this.datafeedAgentClient.addEnforcedAuthenticationScheme(BEARER_AUTH); + + this.datahoseAgentClient.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken)); + this.datahoseAgentClient.addEnforcedAuthenticationScheme(BEARER_AUTH); } } } diff --git a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java index 1ff4ef07a..de3fc0025 100644 --- a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java +++ b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java @@ -4,13 +4,13 @@ import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.AuthenticatorFactory; -import com.symphony.bdk.core.auth.impl.AuthenticatorFactoryImpl; import com.symphony.bdk.core.auth.ExtensionAppTokensRepository; -import com.symphony.bdk.core.auth.impl.OAuthSession; -import com.symphony.bdk.core.auth.impl.OAuthentication; import com.symphony.bdk.core.auth.exception.AuthInitializationException; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; +import com.symphony.bdk.core.auth.impl.AuthenticatorFactoryImpl; import com.symphony.bdk.core.auth.impl.InMemoryTokensRepository; +import com.symphony.bdk.core.auth.impl.OAuthSession; +import com.symphony.bdk.core.auth.impl.OAuthentication; import com.symphony.bdk.core.client.ApiClientFactory; import com.symphony.bdk.core.config.model.BdkConfig; import com.symphony.bdk.http.api.ApiClient; @@ -41,33 +41,33 @@ public ApiClientFactory apiClientFactory(SymphonyBdkCoreProperties properties) { } @Bean(name = "agentApiClient") - public ApiClient agentApiClient(ApiClientFactory apiClientFactory) { - return apiClientFactory.getAgentClient(); + public ApiClient agentApiClient(ApiClientFactory apiClientFactory, Optional botSession, + BdkConfig config) { + ApiClient client = apiClientFactory.getAgentClient(); + addCommonJwtConfig(client, botSession, config); + return client; } @Bean(name = "datafeedAgentApiClient") - public ApiClient datafeedAgentApiClient(ApiClientFactory apiClientFactory) { - return apiClientFactory.getDatafeedAgentClient(); + public ApiClient datafeedAgentApiClient(ApiClientFactory apiClientFactory, Optional botSession, + BdkConfig config) { + ApiClient client = apiClientFactory.getDatafeedAgentClient(); + addCommonJwtConfig(client, botSession, config); + return client; } @Bean(name = "datahoseAgentApiClient") - public ApiClient datahoseAgentApiClient(ApiClientFactory apiClientFactory) { - return apiClientFactory.getDatahoseAgentClient(); + public ApiClient datahoseAgentApiClient(ApiClientFactory apiClientFactory, Optional botSession, + BdkConfig config) { + ApiClient client = apiClientFactory.getDatahoseAgentClient(); + addCommonJwtConfig(client, botSession, config); + return client; } @Bean(name = "podApiClient") public ApiClient podApiClient(ApiClientFactory apiClientFactory, Optional botSession, BdkConfig config) { ApiClient client = apiClientFactory.getPodClient(); - if (config.isCommonJwtEnabled()) { - if (config.isOboConfigured()) { - throw new UnsupportedOperationException( - "Common JWT feature is not available yet in OBO mode, please set commonJwt.enabled to false."); - } else if (botSession.isPresent()) { - final OAuthSession oAuthSession = new OAuthSession(botSession.get()); - client.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken)); - client.addEnforcedAuthenticationScheme(BEARER_AUTH); - } - } + addCommonJwtConfig(client, botSession, config); return client; } @@ -122,4 +122,17 @@ public AuthSession botSession(AuthenticatorFactory authenticatorFactory) { throw new BeanInitializationException("Unable to authenticate bot", e); } } + + private void addCommonJwtConfig(ApiClient client, Optional botSession, BdkConfig config) { + if (config.isCommonJwtEnabled()) { + if (config.isOboConfigured()) { + throw new UnsupportedOperationException( + "Common JWT feature is not available yet in OBO mode, please set commonJwt.enabled to false."); + } else if (botSession.isPresent()) { + final OAuthSession oAuthSession = new OAuthSession(botSession.get()); + client.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken)); + client.addEnforcedAuthenticationScheme(BEARER_AUTH); + } + } + } }