diff --git a/app/client/src/api/CloudServicesApi.ts b/app/client/src/api/CloudServicesApi.ts deleted file mode 100644 index 4817f08830b4..000000000000 --- a/app/client/src/api/CloudServicesApi.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const authorizeDatasourceWithAppsmithToken = (appsmithToken: string) => - `/api/v1/saas/authorize?appsmithToken=${appsmithToken}`; diff --git a/app/client/src/sagas/DatasourcesSagas.ts b/app/client/src/sagas/DatasourcesSagas.ts index c4c50492829b..72ca07924b0f 100644 --- a/app/client/src/sagas/DatasourcesSagas.ts +++ b/app/client/src/sagas/DatasourcesSagas.ts @@ -107,7 +107,6 @@ import { getFormData } from "selectors/formSelectors"; import { getCurrentWorkspaceId } from "ee/selectors/selectedWorkspaceSelectors"; import { getConfigInitialValues } from "components/formControls/utils"; import { setActionProperty } from "actions/pluginActionActions"; -import { authorizeDatasourceWithAppsmithToken } from "api/CloudServicesApi"; import { createMessage, DATASOURCE_CREATE, @@ -711,9 +710,7 @@ function* redirectAuthorizationCodeSaga( pluginType: PluginType; }>, ) { - const { contextId, contextType, datasourceId, pluginType } = - actionPayload.payload; - const isImport: string = yield select(getWorkspaceIdForImport); + const { contextId, datasourceId, pluginType } = actionPayload.payload; const branchName: string | undefined = yield select(getCurrentGitBranch); if (pluginType === PluginType.API) { @@ -728,31 +725,12 @@ function* redirectAuthorizationCodeSaga( window.location.href = windowLocation; } else { - try { - // Get an "appsmith token" from the server - const response: ApiResponse = yield OAuthApi.getAppsmithToken( - datasourceId, - contextId, - contextType, - !!isImport, - ); - - if (validateResponse(response)) { - const appsmithToken = response.data; - - // Save the token for later use once we come back from the auth flow - localStorage.setItem(APPSMITH_TOKEN_STORAGE_KEY, appsmithToken); - // Redirect to the cloud services to authorise - window.location.assign( - authorizeDatasourceWithAppsmithToken(appsmithToken), - ); - } - } catch (e) { - toast.show(OAUTH_AUTHORIZATION_FAILED, { - kind: "error", - }); - log.error(e); - } + toast.show(OAUTH_AUTHORIZATION_FAILED, { + kind: "error", + }); + log.error( + new Error("Can't redirect for authorization for non-API datasource"), + ); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/SaasControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/SaasControllerCE.java index 4b7546d93be5..81028d4b4a78 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/SaasControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/SaasControllerCE.java @@ -2,18 +2,15 @@ import com.appsmith.external.models.OAuth2ResponseDTO; import com.appsmith.external.views.Views; -import com.appsmith.server.configurations.CloudServicesConfig; import com.appsmith.server.constants.FieldName; import com.appsmith.server.constants.Url; import com.appsmith.server.dtos.RequestAppsmithTokenDTO; import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.solutions.AuthenticationService; import com.fasterxml.jackson.annotation.JsonView; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -25,12 +22,14 @@ @Slf4j @RequestMapping(Url.SAAS_URL) -@RequiredArgsConstructor public class SaasControllerCE { private final AuthenticationService authenticationService; - private final CloudServicesConfig cloudServicesConfig; + @Autowired + public SaasControllerCE(AuthenticationService authenticationService) { + this.authenticationService = authenticationService; + } @JsonView(Views.Public.class) @PostMapping("/{datasourceId}/oauth") @@ -64,16 +63,4 @@ public Mono> getAccessToken( .getAccessTokenFromCloud(datasourceId, environmentId, appsmithToken) .map(datasource -> new ResponseDTO<>(HttpStatus.OK.value(), datasource, null)); } - - @GetMapping("authorize") - public Mono redirectForAuthorize(ServerWebExchange exchange, @RequestParam String appsmithToken) { - final String url = cloudServicesConfig.getBaseUrl() + "/api/v1/integrations/oauth/authorize?appsmithToken=" - + appsmithToken; - - ServerHttpResponse response = exchange.getResponse(); - response.setStatusCode(HttpStatus.TEMPORARY_REDIRECT); - response.getHeaders().set("Location", url); - - return response.writeWith(Mono.just(response.bufferFactory().wrap(new byte[] {}))); - } }