diff --git a/components/dashboard/src/App.tsx b/components/dashboard/src/App.tsx index 8259da14dfc1c5..7b874e766c062c 100644 --- a/components/dashboard/src/App.tsx +++ b/components/dashboard/src/App.tsx @@ -47,6 +47,7 @@ import { StartWorkspaceModal } from "./workspaces/StartWorkspaceModal"; import { parseProps } from "./start/StartWorkspace"; import SelectIDEModal from "./settings/SelectIDEModal"; import { StartPage, StartPhase } from "./start/StartPage"; +import { isGitpodIo } from "./utils"; const Setup = React.lazy(() => import(/* webpackPrefetch: true */ "./Setup")); const Workspaces = React.lazy(() => import(/* webpackPrefetch: true */ "./workspaces/Workspaces")); @@ -86,15 +87,6 @@ function Loading() { return <>; } -function isGitpodIo() { - return ( - window.location.hostname === "gitpod.io" || - window.location.hostname === "gitpod-staging.com" || - window.location.hostname.endsWith("gitpod-dev.com") || - window.location.hostname.endsWith("gitpod-io-dev.com") - ); -} - function isWebsiteSlug(pathName: string) { const slugs = [ "about", diff --git a/components/dashboard/src/admin/License.tsx b/components/dashboard/src/admin/License.tsx index 7807b739341a6b..398e950e70bcd0 100644 --- a/components/dashboard/src/admin/License.tsx +++ b/components/dashboard/src/admin/License.tsx @@ -19,6 +19,7 @@ import { ReactComponent as CheckSvg } from "../images/check.svg"; import { ReactComponent as LinkSvg } from "../images/external-link.svg"; import SolidCard from "../components/SolidCard"; import Card from "../components/Card"; +import { isGitpodIo } from "../utils"; export default function License() { const { license, setLicense } = useContext(LicenseContext); @@ -212,7 +213,3 @@ function communityPlan(userCount: number, seats: number, fallbackAllowed: boolea return [licenseLevel("Community"), additionalLicenseInfo("Free"), alertMessage(aboveLimit)]; } - -function isGitpodIo() { - return window.location.hostname === "gitpod.io" || window.location.hostname === "gitpod-staging.com"; -} diff --git a/components/dashboard/src/admin/Settings.tsx b/components/dashboard/src/admin/Settings.tsx index 3869af5fe41f68..d901fd2a83b1c3 100644 --- a/components/dashboard/src/admin/Settings.tsx +++ b/components/dashboard/src/admin/Settings.tsx @@ -13,6 +13,7 @@ import { getGitpodService } from "../service/service"; import { adminMenu } from "./admin-menu"; import { useEffect, useState } from "react"; import InfoBox from "../components/InfoBox"; +import { isGitpodIo } from "../utils"; export default function Settings() { const { adminSettings, setAdminSettings } = useContext(AdminContext); @@ -69,7 +70,3 @@ export default function Settings() { ); } - -function isGitpodIo() { - return window.location.hostname === "gitpod.io" || window.location.hostname === "gitpod-staging.com"; -} diff --git a/components/dashboard/src/settings/Integrations.tsx b/components/dashboard/src/settings/Integrations.tsx index a514a7ca48ac59..a73ccdb47aa7b3 100644 --- a/components/dashboard/src/settings/Integrations.tsx +++ b/components/dashboard/src/settings/Integrations.tsx @@ -21,6 +21,7 @@ import { PaymentContext } from "../payment-context"; import { openAuthorizeWindow } from "../provider-utils"; import { getGitpodService, gitpodHostUrl } from "../service/service"; import { UserContext } from "../user-context"; +import { isGitpodIo } from "../utils"; import { SelectAccountModal } from "./SelectAccountModal"; import getSettingsMenu from "./settings-menu"; @@ -553,6 +554,13 @@ export function GitIntegrationModal( validate(); }, [clientId, clientSecret, type]); + // "bitbucket.org" is set as host value whenever "Bitbucket" is selected + useEffect(() => { + if (props.mode === "new") { + updateHostValue(type === "Bitbucket" ? "bitbucket.org" : ""); + } + }, [type]); + const onClose = () => props.onClose && props.onClose(); const onUpdate = () => props.onUpdate && props.onUpdate(); @@ -696,11 +704,11 @@ export function GitIntegrationModal( return ( Use this redirect URL to update the OAuth application. Go to{" "} - + developer settings {" "} and setup the OAuth application.  - + Learn more . @@ -716,6 +724,8 @@ export function GitIntegrationModal( return "gitlab.example.com"; case "BitbucketServer": return "bitbucket.example.com"; + case "Bitbucket": + return "bitbucket.org"; default: return ""; } @@ -762,6 +772,7 @@ export function GitIntegrationModal( > + {!isGitpodIo() && } @@ -785,7 +796,7 @@ export function GitIntegrationModal( ( } } }; + +export function isGitpodIo() { + return ( + window.location.hostname === "gitpod.io" || + window.location.hostname === "gitpod-staging.com" || + window.location.hostname.endsWith("gitpod-dev.com") || + window.location.hostname.endsWith("gitpod-io-dev.com") + ); +} diff --git a/components/server/src/auth/auth-provider-service.ts b/components/server/src/auth/auth-provider-service.ts index a7178f59f37ea8..c706aeb25761ae 100644 --- a/components/server/src/auth/auth-provider-service.ts +++ b/components/server/src/auth/auth-provider-service.ts @@ -13,6 +13,7 @@ import { v4 as uuidv4 } from "uuid"; import { oauthUrls as githubUrls } from "../github/github-urls"; import { oauthUrls as gitlabUrls } from "../gitlab/gitlab-urls"; import { oauthUrls as bbsUrls } from "../bitbucket-server/bitbucket-server-urls"; +import { oauthUrls as bbUrls } from "../bitbucket/bitbucket-urls"; import { log } from "@gitpod/gitpod-protocol/lib/util/logging"; @injectable() @@ -123,6 +124,9 @@ export class AuthProviderService { case "BitbucketServer": urls = bbsUrls(host); break; + case "Bitbucket": + urls = bbUrls(host); + break; } if (!urls) { throw new Error("Unexpected service type."); diff --git a/components/server/src/bitbucket/bitbucket-urls.ts b/components/server/src/bitbucket/bitbucket-urls.ts new file mode 100644 index 00000000000000..99b39f233e23a5 --- /dev/null +++ b/components/server/src/bitbucket/bitbucket-urls.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2022 Gitpod GmbH. All rights reserved. + * Licensed under the GNU Affero General Public License (AGPL). + * See License-AGPL.txt in the project root for license information. + */ + +// cf. https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/ +// +export function oauthUrls(host: string) { + return { + authorizationUrl: `https://${host}/site/oauth2/authorize`, + tokenUrl: `https://${host}/site/oauth2/access_token`, + settingsUrl: `https://${host}/account/settings/app-authorizations/`, + }; +}