Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/OauthClientApproval.tsx
2498 views
1
/**
2
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { Button } from "@podkit/buttons/Button";
8
import gitpodIcon from "./icons/gitpod.svg";
9
import { Heading1, Subheading } from "@podkit/typography/Headings";
10
import { isTrustedUrlOrPath } from "./utils";
11
12
export default function OAuthClientApproval() {
13
const params = new URLSearchParams(window.location.search);
14
const clientName = params.get("clientName") || "";
15
16
let redirectTo = "/";
17
const returnToPath = params.get("returnToPath");
18
if (returnToPath) {
19
const isAbsoluteURL = /^https?:\/\//i.test(returnToPath);
20
if (!isAbsoluteURL) {
21
redirectTo = returnToPath;
22
}
23
}
24
const updateClientApproval = async (isApproved: boolean) => {
25
if (redirectTo === "/") {
26
window.location.replace(redirectTo);
27
return;
28
}
29
const url = `${redirectTo}&approved=${isApproved ? "yes" : "no"}`;
30
if (isTrustedUrlOrPath(url)) {
31
window.location.replace(url);
32
}
33
};
34
35
return (
36
<div id="oauth-container" className="z-50 flex w-screen h-screen">
37
<div id="oauth-section" className="flex-grow flex w-full">
38
<div id="oauth-section-column" className="flex-grow max-w-2xl flex flex-col h-100 mx-auto">
39
<div className="flex-grow h-100 flex flex-row items-center justify-center">
40
<div className="rounded-xl px-10 py-10 mx-auto">
41
<div className="mx-auto pb-8">
42
<img src={gitpodIcon} className="h-16 mx-auto" alt="Gitpod's logo" />
43
</div>
44
<div className="mx-auto text-center pb-8 space-y-2">
45
<Heading1>Authorize {clientName}</Heading1>
46
<Subheading>
47
You are about to authorize {clientName} to access your Gitpod account including data
48
for all workspaces.
49
</Subheading>
50
</div>
51
<div className="flex justify-center mt-6">
52
<Button variant="secondary" onClick={() => updateClientApproval(false)}>
53
Cancel
54
</Button>
55
<Button key={"button-yes"} className="ml-2" onClick={() => updateClientApproval(true)}>
56
Authorize
57
</Button>
58
</div>
59
</div>
60
</div>
61
</div>
62
</div>
63
</div>
64
);
65
}
66
67