|
4 | 4 |
|
5 | 5 | import com.symphony.bdk.core.auth.AuthSession; |
6 | 6 | import com.symphony.bdk.core.auth.AuthenticatorFactory; |
7 | | -import com.symphony.bdk.core.auth.impl.AuthenticatorFactoryImpl; |
8 | 7 | import com.symphony.bdk.core.auth.ExtensionAppTokensRepository; |
9 | | -import com.symphony.bdk.core.auth.impl.OAuthSession; |
10 | | -import com.symphony.bdk.core.auth.impl.OAuthentication; |
11 | 8 | import com.symphony.bdk.core.auth.exception.AuthInitializationException; |
12 | 9 | import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; |
| 10 | +import com.symphony.bdk.core.auth.impl.AuthenticatorFactoryImpl; |
13 | 11 | import com.symphony.bdk.core.auth.impl.InMemoryTokensRepository; |
| 12 | +import com.symphony.bdk.core.auth.impl.OAuthSession; |
| 13 | +import com.symphony.bdk.core.auth.impl.OAuthentication; |
14 | 14 | import com.symphony.bdk.core.client.ApiClientFactory; |
15 | 15 | import com.symphony.bdk.core.config.model.BdkConfig; |
16 | 16 | import com.symphony.bdk.http.api.ApiClient; |
@@ -41,33 +41,33 @@ public ApiClientFactory apiClientFactory(SymphonyBdkCoreProperties properties) { |
41 | 41 | } |
42 | 42 |
|
43 | 43 | @Bean(name = "agentApiClient") |
44 | | - public ApiClient agentApiClient(ApiClientFactory apiClientFactory) { |
45 | | - return apiClientFactory.getAgentClient(); |
| 44 | + public ApiClient agentApiClient(ApiClientFactory apiClientFactory, Optional<AuthSession> botSession, |
| 45 | + BdkConfig config) { |
| 46 | + ApiClient client = apiClientFactory.getAgentClient(); |
| 47 | + addCommonJwtConfig(client, botSession, config); |
| 48 | + return client; |
46 | 49 | } |
47 | 50 |
|
48 | 51 | @Bean(name = "datafeedAgentApiClient") |
49 | | - public ApiClient datafeedAgentApiClient(ApiClientFactory apiClientFactory) { |
50 | | - return apiClientFactory.getDatafeedAgentClient(); |
| 52 | + public ApiClient datafeedAgentApiClient(ApiClientFactory apiClientFactory, Optional<AuthSession> botSession, |
| 53 | + BdkConfig config) { |
| 54 | + ApiClient client = apiClientFactory.getDatafeedAgentClient(); |
| 55 | + addCommonJwtConfig(client, botSession, config); |
| 56 | + return client; |
51 | 57 | } |
52 | 58 |
|
53 | 59 | @Bean(name = "datahoseAgentApiClient") |
54 | | - public ApiClient datahoseAgentApiClient(ApiClientFactory apiClientFactory) { |
55 | | - return apiClientFactory.getDatahoseAgentClient(); |
| 60 | + public ApiClient datahoseAgentApiClient(ApiClientFactory apiClientFactory, Optional<AuthSession> botSession, |
| 61 | + BdkConfig config) { |
| 62 | + ApiClient client = apiClientFactory.getDatahoseAgentClient(); |
| 63 | + addCommonJwtConfig(client, botSession, config); |
| 64 | + return client; |
56 | 65 | } |
57 | 66 |
|
58 | 67 | @Bean(name = "podApiClient") |
59 | 68 | public ApiClient podApiClient(ApiClientFactory apiClientFactory, Optional<AuthSession> botSession, BdkConfig config) { |
60 | 69 | ApiClient client = apiClientFactory.getPodClient(); |
61 | | - if (config.isCommonJwtEnabled()) { |
62 | | - if (config.isOboConfigured()) { |
63 | | - throw new UnsupportedOperationException( |
64 | | - "Common JWT feature is not available yet in OBO mode, please set commonJwt.enabled to false."); |
65 | | - } else if (botSession.isPresent()) { |
66 | | - final OAuthSession oAuthSession = new OAuthSession(botSession.get()); |
67 | | - client.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken)); |
68 | | - client.addEnforcedAuthenticationScheme(BEARER_AUTH); |
69 | | - } |
70 | | - } |
| 70 | + addCommonJwtConfig(client, botSession, config); |
71 | 71 | return client; |
72 | 72 | } |
73 | 73 |
|
@@ -122,4 +122,17 @@ public AuthSession botSession(AuthenticatorFactory authenticatorFactory) { |
122 | 122 | throw new BeanInitializationException("Unable to authenticate bot", e); |
123 | 123 | } |
124 | 124 | } |
| 125 | + |
| 126 | + private void addCommonJwtConfig(ApiClient client, Optional<AuthSession> botSession, BdkConfig config) { |
| 127 | + if (config.isCommonJwtEnabled()) { |
| 128 | + if (config.isOboConfigured()) { |
| 129 | + throw new UnsupportedOperationException( |
| 130 | + "Common JWT feature is not available yet in OBO mode, please set commonJwt.enabled to false."); |
| 131 | + } else if (botSession.isPresent()) { |
| 132 | + final OAuthSession oAuthSession = new OAuthSession(botSession.get()); |
| 133 | + client.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken)); |
| 134 | + client.addEnforcedAuthenticationScheme(BEARER_AUTH); |
| 135 | + } |
| 136 | + } |
| 137 | + } |
125 | 138 | } |
0 commit comments