Skip to content

Commit

Permalink
SUPPORT-29677 fix login for all regions
Browse files Browse the repository at this point in the history
  • Loading branch information
lojzatran committed Nov 26, 2024
1 parent f5d4917 commit 1bd0f64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public CtpReactiveAuthenticationManagerResolver(final ApiHttpClient apiHttpClien
@Override
public Mono<ReactiveAuthenticationManager> resolve(final ServerWebExchange context) {
return Mono.just(new CtpReactiveAuthenticationManager(meClient(apiHttpClient, context.getSession()),
credentials(), projectKey));
credentials(), projectKey, authUrl));
}

private ProjectApiRoot meClient(final ApiHttpClient client, final Mono<WebSession> session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import reactor.core.publisher.Mono;

public class CtpReactiveAuthenticationManager implements ReactiveAuthenticationManager {
private final String authUrl;
VrapHttpClient client;
ProjectApiRoot apiRoot;

Expand All @@ -33,11 +34,12 @@ public class CtpReactiveAuthenticationManager implements ReactiveAuthenticationM
private final String projectKey;

public CtpReactiveAuthenticationManager(final ProjectApiRoot apiRoot, final ClientCredentials credentials,
final String projectKey) {
final String projectKey, final String authUrl) {
this.apiRoot = apiRoot;
this.client = HttpClientSupplier.of().get();
this.credentials = credentials;
this.projectKey = projectKey;
this.authUrl = authUrl;
}

@Override
Expand All @@ -54,10 +56,12 @@ public Mono<Authentication> authenticate(Authentication authentication) {
.fromFuture(
apiRoot.me().login().post(customerSignin.build()).execute().exceptionally(throwable -> null))
.flatMap(customerSignInResultApiHttpResponse -> {
String passwordFlowTokenURL = this.authUrl != null
? this.authUrl + "/oauth/" + projectKey + "/customers/token"
: ServiceRegion.GCP_EUROPE_WEST1.getPasswordFlowTokenURL(projectKey);
GlobalCustomerPasswordTokenSupplier supplier = new GlobalCustomerPasswordTokenSupplier(
credentials.getClientId(), credentials.getClientSecret(), authentication.getName(),
authentication.getCredentials().toString(), null,
ServiceRegion.GCP_EUROPE_WEST1.getPasswordFlowTokenURL(projectKey), client);
authentication.getCredentials().toString(), null, passwordFlowTokenURL, client);

return Mono.zip(Mono.fromFuture(supplier.getToken().exceptionally(throwable -> null)),
Mono.just(customerSignInResultApiHttpResponse.getBody()));
Expand Down

0 comments on commit 1bd0f64

Please sign in to comment.