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