From 37075cddcb68b14ca637945cdf907444e88239cb Mon Sep 17 00:00:00 2001 From: Aneela Chagarlamudi Date: Mon, 24 Jun 2024 16:25:45 +0200 Subject: [PATCH] Add static redirect page to sso and then to requested page [RHCLOUD-32115] --- pkg/assets/static/redirectpage.html | 12 +++++++ pkg/assets/static/redirectpage.js | 53 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 pkg/assets/static/redirectpage.html create mode 100644 pkg/assets/static/redirectpage.js diff --git a/pkg/assets/static/redirectpage.html b/pkg/assets/static/redirectpage.html new file mode 100644 index 00000000..b69891c8 --- /dev/null +++ b/pkg/assets/static/redirectpage.html @@ -0,0 +1,12 @@ + + + + + + OpenShift Developer Sandbox + + + + + + diff --git a/pkg/assets/static/redirectpage.js b/pkg/assets/static/redirectpage.js new file mode 100644 index 00000000..fd72f727 --- /dev/null +++ b/pkg/assets/static/redirectpage.js @@ -0,0 +1,53 @@ +const queryString = window.location.search; +const urlParams = new URLSearchParams(queryString); +const link = urlParams.get("link"); +const keyword = urlParams.get("keyword"); +const selectedId = urlParams.get("selectedId"); +const consoleUrl = "https://console.redhat.com/openshift/sandbox"; +const baseUrl = `https://${data.consoleURL}/`; +const appendedUrl = `${link}/ns/${data.defaultUserNamespace}`; +const params = { + keyword, + selectedId, +}; +const redirectUrl = new URL(baseUrl + appendedUrl); + +Object.keys(params).forEach((key) => { + if (params[key]) { + urlParams.searchParams.append(key, params[key]); + } +}); + +function handleSuccess(data) { + if (data.status != "ready") { + window.location.href = "https://console.redhat.com/openshift/sandbox"; + } else { + window.location.href = + link === "notebookController" + ? `${baseUrl}notebookController/spawner` + : link === "dashboard" + ? `${baseUrl}dashboard` + : redirectUrl.toString(); + } +} + +function handleError() { + window.location.href = "https://console.redhat.com/openshift/sandbox"; +} + +if (keycloak) { + fetch( + "registration-service-toolchain-host-operator.apps.sandbox.x8i5.p1.openshiftapps.com/api/v1/signup", + { + method: "GET", + headers: { + Authorization: "Bearer" + keycloak.token, + }, + } + ) + .then((response) => response.json()) + .then((data) => handleSuccess(data)) + .catch((error) => handleError(error)); +} else { + login(); +}