Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AuthSession> 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<AuthSession> 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<AuthSession> botSession,
BdkConfig config) {
ApiClient client = apiClientFactory.getDatahoseAgentClient();
addCommonJwtConfig(client, botSession, config);
return client;
}

@Bean(name = "podApiClient")
public ApiClient podApiClient(ApiClientFactory apiClientFactory, Optional<AuthSession> 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;
}

Expand Down Expand Up @@ -122,4 +122,17 @@ public AuthSession botSession(AuthenticatorFactory authenticatorFactory) {
throw new BeanInitializationException("Unable to authenticate bot", e);
}
}

private void addCommonJwtConfig(ApiClient client, Optional<AuthSession> 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);
}
}
}
}
Loading