diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/IntegrationDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/IntegrationDTO.java index 709744c36f..4a0eb2eee1 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/IntegrationDTO.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/IntegrationDTO.java @@ -18,6 +18,8 @@ public class IntegrationDTO { String datasourceId; + String workspaceId; + String applicationId; String pageId; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java index ff52df46a8..400391f4db 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java @@ -116,6 +116,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { .flatMap(datasource -> datasourceService.getTrueEnvironmentId( datasource.getWorkspaceId(), environmentId, datasource.getPluginId(), null)) .cache(); + Mono workspaceIdMono = datasourceMonoCached.map(Datasource::getWorkspaceId); return datasourceMonoCached .zipWith(trueEnvironmentIdCached) @@ -127,16 +128,18 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { .switchIfEmpty(Mono.error( new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.DATASOURCE, datasourceId))) .flatMap(this::validateRequiredFieldsForGenericOAuth2) - .zipWith(trueEnvironmentIdCached) + .zipWith(Mono.zip(workspaceIdMono, trueEnvironmentIdCached)) .flatMap(tuple2 -> { DatasourceStorage datasourceStorage = tuple2.getT1(); - String trueEnvironmentId = tuple2.getT2(); + String workspaceId = tuple2.getT2().getT1(); + String trueEnvironmentId = tuple2.getT2().getT2(); OAuth2 oAuth2 = (OAuth2) datasourceStorage.getDatasourceConfiguration().getAuthentication(); final String redirectUri = redirectHelper.getRedirectDomain(httpRequest.getHeaders()); final String state = StringUtils.hasText(branchName) - ? String.join(",", pageId, datasourceId, trueEnvironmentId, redirectUri, branchName) - : String.join(",", pageId, datasourceId, trueEnvironmentId, redirectUri); + ? String.join( + ",", pageId, datasourceId, trueEnvironmentId, redirectUri, workspaceId, branchName) + : String.join(",", pageId, datasourceId, trueEnvironmentId, redirectUri, workspaceId); // Adding basic uri components UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString( oAuth2.getAuthorizationUrl()) @@ -332,7 +335,8 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { final String datasourceId = splitState[1]; final String environmentId = splitState[2]; final String redirectOrigin = splitState[3]; - final String branchName = splitState.length == 5 ? splitState[4] : null; + final String workspaceId = splitState[4]; + final String branchName = splitState.length == 6 ? splitState[5] : null; String response = SUCCESS; if (error != null) { response = error; @@ -350,6 +354,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { + "?response_status=" + responseStatus + "&view_mode=true" + + (StringUtils.hasText(workspaceId) ? "&workspaceId=" + workspaceId : "") + (StringUtils.hasText(branchName) ? "&branch=" + branchName : "")) .onErrorResume(e -> Mono.just(redirectOrigin + Entity.SLASH + Entity.APPLICATIONS + "?response_status=" @@ -415,6 +420,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { integrationDTO.setApplicationId(defaultApplicationId); integrationDTO.setBranch(branchName); integrationDTO.setImportForGit(importForGit); + integrationDTO.setWorkspaceId(datasource.getWorkspaceId()); final Plugin plugin = tuple.getT3(); integrationDTO.setPluginName(plugin.getPluginName()); integrationDTO.setPluginVersion(plugin.getVersion()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/AuthenticationServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/AuthenticationServiceTest.java index 1a578ff318..d861b6ffc3 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/AuthenticationServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/AuthenticationServiceTest.java @@ -242,7 +242,8 @@ public class AuthenticationServiceTest { pageDto.getId(), datasourceId1, defaultEnvironmentId, - "https://mock.origin.com") + "https://mock.origin.com", + workspace.getId()) + "&scope=Scope\\d%20Scope\\d" + "&key=value")); }) @@ -336,6 +337,7 @@ public class AuthenticationServiceTest { datasourceId, defaultEnvironmentId, "https://mock.origin.com", + workspaceId, "testBranch") + "&scope=Scope\\d%20Scope\\d" + "&key=value"));