Skip to content

Commit

Permalink
Add static redirect page to sso and then to requested page
Browse files Browse the repository at this point in the history
[RHCLOUD-32115]
  • Loading branch information
aneelac22 committed Sep 10, 2024
1 parent 22b13b9 commit 37075cd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/assets/static/redirectpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en" class="pf-m-redhat-font">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>OpenShift Developer Sandbox</title>
</head>
<body>
</body>
<script src="landingpage.js"></script>
<script src="redirectpage.js"></script>
</html>
53 changes: 53 additions & 0 deletions pkg/assets/static/redirectpage.js
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 37075cd

Please sign in to comment.