diff --git a/components/dashboard/src/components/AuthorizeGit.tsx b/components/dashboard/src/components/AuthorizeGit.tsx
index 96e945b1aa8cd9..cbb239fc7cf86b 100644
--- a/components/dashboard/src/components/AuthorizeGit.tsx
+++ b/components/dashboard/src/components/AuthorizeGit.tsx
@@ -4,10 +4,9 @@
* See License.AGPL.txt in the project root for license information.
*/
-import { AuthProviderInfo } from "@gitpod/gitpod-protocol";
import { FC, useCallback, useContext } from "react";
import { Link } from "react-router-dom";
-import { useAuthProviders } from "../data/auth-providers/auth-provider-query";
+import { useAuthProviderDescriptions } from "../data/auth-providers/auth-provider-query";
import { openAuthorizeWindow } from "../provider-utils";
import { getGitpodService } from "../service/service";
import { UserContext, useCurrentUser } from "../user-context";
@@ -16,29 +15,29 @@ import { Heading2, Heading3, Subheading } from "./typography/headings";
import classNames from "classnames";
import { iconForAuthProvider, simplifyProviderName } from "../provider-utils";
import { useIsOwner } from "../data/organizations/members-query";
+import { AuthProviderDescription } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
export function useNeedsGitAuthorization() {
- const authProviders = useAuthProviders();
+ const authProviders = useAuthProviderDescriptions();
const user = useCurrentUser();
if (!user || !authProviders.data) {
return false;
}
- return !authProviders.data.some((ap) => user.identities.some((i) => ap.authProviderId === i.authProviderId));
+ return !authProviders.data.some((ap) => user.identities.some((i) => ap.id === i.authProviderId));
}
export const AuthorizeGit: FC<{ className?: string }> = ({ className }) => {
const { setUser } = useContext(UserContext);
const owner = useIsOwner();
- const authProviders = useAuthProviders();
+ const authProviders = useAuthProviderDescriptions();
const updateUser = useCallback(() => {
getGitpodService().server.getLoggedInUser().then(setUser);
}, [setUser]);
const connect = useCallback(
- (ap: AuthProviderInfo) => {
+ (ap: AuthProviderDescription) => {
openAuthorizeWindow({
host: ap.host,
- scopes: ap.requirements?.default,
overrideScopes: true,
onSuccess: updateUser,
});
@@ -91,7 +90,7 @@ export const AuthorizeGit: FC<{ className?: string }> = ({ className }) => {
className="mt-3 btn-login flex-none w-56 px-0 py-0.5 inline-flex"
>
- {iconForAuthProvider(ap.authProviderType)}
+ {iconForAuthProvider(ap.type)}
Continue with {simplifyProviderName(ap.host)}
diff --git a/components/dashboard/src/components/RepositoryFinder.tsx b/components/dashboard/src/components/RepositoryFinder.tsx
index 3f185b8e527f2c..309b9ec625c77d 100644
--- a/components/dashboard/src/components/RepositoryFinder.tsx
+++ b/components/dashboard/src/components/RepositoryFinder.tsx
@@ -11,8 +11,9 @@ import { ReactComponent as RepositoryIcon } from "../icons/RepositoryWithColor.s
import { SuggestedRepository } from "@gitpod/gitpod-protocol";
import { MiddleDot } from "./typography/MiddleDot";
import { useUnifiedRepositorySearch } from "../data/git-providers/unified-repositories-search-query";
-import { useAuthProviders } from "../data/auth-providers/auth-provider-query";
+import { useAuthProviderDescriptions } from "../data/auth-providers/auth-provider-query";
import { ReactComponent as Exclamation2 } from "../images/exclamation2.svg";
+import { AuthProviderType } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
interface RepositoryFinderProps {
selectedContextURL?: string;
@@ -39,7 +40,7 @@ export default function RepositoryFinder({
hasMore,
} = useUnifiedRepositorySearch({ searchString, excludeProjects });
- const authProviders = useAuthProviders();
+ const authProviders = useAuthProviderDescriptions();
const handleSelectionChange = useCallback(
(selectedID: string) => {
@@ -115,7 +116,10 @@ export default function RepositoryFinder({
isSelectable: false,
} as ComboboxElement);
}
- if (searchString.length >= 3 && authProviders.data?.some((p) => p.authProviderType === "BitbucketServer")) {
+ if (
+ searchString.length >= 3 &&
+ authProviders.data?.some((p) => p.type === AuthProviderType.BITBUCKET_SERVER)
+ ) {
// add an element that tells the user that the Bitbucket Server does only support prefix search
result.push({
id: "bitbucket-server",
diff --git a/components/dashboard/src/data/auth-providers/auth-provider-query.ts b/components/dashboard/src/data/auth-providers/auth-provider-query.ts
index eba3cc9741f354..d4bafde79e4d45 100644
--- a/components/dashboard/src/data/auth-providers/auth-provider-query.ts
+++ b/components/dashboard/src/data/auth-providers/auth-provider-query.ts
@@ -4,9 +4,7 @@
* See License.AGPL.txt in the project root for license information.
*/
-import { AuthProviderInfo } from "@gitpod/gitpod-protocol";
import { useQuery } from "@tanstack/react-query";
-import { getGitpodService } from "../../service/service";
import { authProviderClient } from "../../service/public-api";
import { useCurrentUser } from "../../user-context";
import {
@@ -14,15 +12,6 @@ import {
ListAuthProviderDescriptionsRequest,
} from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
-export const useAuthProviders = () => {
- return useQuery
({
- queryKey: ["auth-providers"],
- queryFn: async () => {
- return await getGitpodService().server.getAuthProviders();
- },
- });
-};
-
export const useAuthProviderDescriptions = () => {
const user = useCurrentUser();
const query = useQuery({
diff --git a/components/dashboard/src/projects/NewProject.tsx b/components/dashboard/src/projects/NewProject.tsx
index 315f4b33da6e6c..905894d60ce89d 100644
--- a/components/dashboard/src/projects/NewProject.tsx
+++ b/components/dashboard/src/projects/NewProject.tsx
@@ -4,7 +4,7 @@
* See License.AGPL.txt in the project root for license information.
*/
-import { AuthProviderInfo, Project } from "@gitpod/gitpod-protocol";
+import { Project } from "@gitpod/gitpod-protocol";
import { FC, useCallback, useContext, useEffect, useMemo, useState } from "react";
import ErrorMessage from "../components/ErrorMessage";
import { useCurrentOrg } from "../data/organizations/orgs-query";
@@ -13,19 +13,20 @@ import { iconForAuthProvider, openAuthorizeWindow, simplifyProviderName } from "
import { getGitpodService } from "../service/service";
import { UserContext, useCurrentUser } from "../user-context";
import { Heading1, Subheading } from "../components/typography/headings";
-import { useAuthProviders } from "../data/auth-providers/auth-provider-query";
+import { useAuthProviderDescriptions } from "../data/auth-providers/auth-provider-query";
import { AuthorizeGit, useNeedsGitAuthorization } from "../components/AuthorizeGit";
import { NewProjectRepoSelection } from "./new-project/NewProjectRepoSelection";
import { NewProjectSubheading } from "./new-project/NewProjectSubheading";
import { Button } from "../components/Button";
+import { AuthProviderDescription, AuthProviderType } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
export default function NewProject() {
const currentTeam = useCurrentOrg()?.data;
const user = useCurrentUser();
- const authProviders = useAuthProviders();
+ const authProviders = useAuthProviderDescriptions();
// State this component manages
- const [selectedProvider, setSelectedProvider] = useState();
+ const [selectedProvider, setSelectedProvider] = useState();
const [project, setProject] = useState();
// Defaults selectedProviderHost if not set yet
@@ -34,9 +35,7 @@ export default function NewProject() {
for (let i = user.identities.length - 1; i >= 0; i--) {
const candidate = user.identities[i];
if (candidate) {
- const authProvider = authProviders.data.find(
- (ap) => ap.authProviderId === candidate.authProviderId,
- );
+ const authProvider = authProviders.data.find((ap) => ap.id === candidate.authProviderId);
if (authProvider) {
setSelectedProvider(authProvider);
break;
@@ -107,8 +106,8 @@ export default function NewProject() {
}
type NewProjectMainContentProps = {
- selectedProvider?: AuthProviderInfo;
- onProviderSelected: (ap: AuthProviderInfo, updateUser?: boolean) => void;
+ selectedProvider?: AuthProviderDescription;
+ onProviderSelected: (ap: AuthProviderDescription, updateUser?: boolean) => void;
onProjectCreated: (project: Project) => void;
};
const NewProjectMainContent: FC = ({
@@ -117,12 +116,12 @@ const NewProjectMainContent: FC = ({
onProjectCreated,
}) => {
const { setUser } = useContext(UserContext);
- const authProviders = useAuthProviders();
+ const authProviders = useAuthProviderDescriptions();
const needsGitAuth = useNeedsGitAuthorization();
const [showGitProviders, setShowGitProviders] = useState(false);
const onGitProviderSeleted = useCallback(
- async (ap: AuthProviderInfo, updateUser?: boolean) => {
+ async (ap: AuthProviderDescription, updateUser?: boolean) => {
// TODO: Can we push this down into where sends updateUser=true?
if (updateUser) {
setUser(await getGitpodService().server.getLoggedInUser());
@@ -151,23 +150,22 @@ const NewProjectMainContent: FC = ({
};
const GitProviders: FC<{
- authProviders: AuthProviderInfo[];
- onProviderSelected: (ap: AuthProviderInfo, updateUser?: boolean) => void;
+ authProviders: AuthProviderDescription[];
+ onProviderSelected: (ap: AuthProviderDescription, updateUser?: boolean) => void;
}> = ({ authProviders, onProviderSelected }) => {
const [errorMessage, setErrorMessage] = useState(undefined);
const selectProvider = useCallback(
- async (ap: AuthProviderInfo) => {
+ async (ap: AuthProviderDescription) => {
setErrorMessage(undefined);
const token = await getGitpodService().server.getToken({ host: ap.host });
- if (token && !(ap.authProviderType === "GitHub" && !token.scopes.includes("repo"))) {
+ if (token && !(ap.type === AuthProviderType.GITHUB && !token.scopes.includes("repo"))) {
onProviderSelected(ap);
return;
}
await openAuthorizeWindow({
host: ap.host,
- scopes: ap.authProviderType === "GitHub" ? ["repo"] : ap.requirements?.default,
onSuccess: async () => {
onProviderSelected(ap, true);
},
@@ -194,10 +192,10 @@ const GitProviders: FC<{
() =>
authProviders.filter(
(p) =>
- p.authProviderType === "GitHub" ||
+ p.type === AuthProviderType.GITHUB ||
p.host === "bitbucket.org" ||
- p.authProviderType === "GitLab" ||
- p.authProviderType === "BitbucketServer",
+ p.type === AuthProviderType.GITLAB ||
+ p.type === AuthProviderType.BITBUCKET_SERVER,
),
[authProviders],
);
@@ -216,7 +214,7 @@ const GitProviders: FC<{
className="btn-login flex-none w-56 h-10 p-0 inline-flex"
onClick={() => selectProvider(ap)}
>
- {iconForAuthProvider(ap.authProviderType)}
+ {iconForAuthProvider(ap.type)}
Continue with {simplifyProviderName(ap.host)}
diff --git a/components/dashboard/src/projects/new-project/NewProjectAuthRequired.tsx b/components/dashboard/src/projects/new-project/NewProjectAuthRequired.tsx
index aef5370d501f7a..cb2da4446427b9 100644
--- a/components/dashboard/src/projects/new-project/NewProjectAuthRequired.tsx
+++ b/components/dashboard/src/projects/new-project/NewProjectAuthRequired.tsx
@@ -5,7 +5,7 @@
*/
import { FC, useCallback } from "react";
-import { useAuthProviders } from "../../data/auth-providers/auth-provider-query";
+import { useAuthProviderDescriptions } from "../../data/auth-providers/auth-provider-query";
import { openAuthorizeWindow } from "../../provider-utils";
type Props = {
@@ -18,7 +18,7 @@ export const NewProjectAuthRequired: FC = ({
areGitHubWebhooksUnauthorized = false,
onReconfigure,
}) => {
- const authProviders = useAuthProviders();
+ const authProviders = useAuthProviderDescriptions();
const handleAuthorize = useCallback(() => {
const ap = authProviders.data?.find((ap) => ap.host === selectedProviderHost);
@@ -27,12 +27,8 @@ export const NewProjectAuthRequired: FC = ({
}
openAuthorizeWindow({
host: ap.host,
- scopes: ap.authProviderType === "GitHub" ? ["repo"] : ap.requirements?.default,
onSuccess: async () => {
- // TODO: Verify this works correctly
- if (ap.authProviderType === "GitHub") {
- authProviders.refetch();
- }
+ authProviders.refetch();
},
onError: (payload) => {
console.error("Authorization failed", selectedProviderHost, payload);
diff --git a/components/dashboard/src/projects/new-project/NewProjectRepoSelection.tsx b/components/dashboard/src/projects/new-project/NewProjectRepoSelection.tsx
index 7cf489f1d0b22f..2fad3a5a90b949 100644
--- a/components/dashboard/src/projects/new-project/NewProjectRepoSelection.tsx
+++ b/components/dashboard/src/projects/new-project/NewProjectRepoSelection.tsx
@@ -4,7 +4,7 @@
* See License.AGPL.txt in the project root for license information.
*/
-import { AuthProviderInfo, Project } from "@gitpod/gitpod-protocol";
+import { Project } from "@gitpod/gitpod-protocol";
import { FC, useCallback, useEffect, useMemo, useState } from "react";
import { useAreGithubWebhooksUnauthorized, useIsGithubAppEnabled } from "../../data/git-providers/github-queries";
import { LinkButton } from "../../components/LinkButton";
@@ -22,9 +22,10 @@ import { NewProjectCreateFromURL } from "./NewProjectCreateFromURL";
import { useStateWithDebounce } from "../../hooks/use-state-with-debounce";
import { useFeatureFlag } from "../../data/featureflag-query";
import Alert from "../../components/Alert";
+import { AuthProviderDescription, AuthProviderType } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
type Props = {
- selectedProvider?: AuthProviderInfo;
+ selectedProvider?: AuthProviderDescription;
onProjectCreated: (project: Project) => void;
onChangeGitProvider: () => void;
};
@@ -59,7 +60,7 @@ export const NewProjectRepoSelection: FC = ({ selectedProvider, onProject
// Memoized & derived values
const noReposAvailable = !!(reposInAccounts?.length === 0 || areGitHubWebhooksUnauthorized);
const isGitHub = selectedProvider?.host === "github.com";
- const isBitbucketServer = selectedProvider?.authProviderType === "BitbucketServer";
+ const isBitbucketServer = selectedProvider?.type === AuthProviderType.BITBUCKET_SERVER;
const enableBBSIncrementalSearch = isBitbucketServer && newProjectIncrementalRepoSearchBBS;
const accounts = useMemo(() => {
diff --git a/components/dashboard/src/provider-utils.tsx b/components/dashboard/src/provider-utils.tsx
index 22cb8bfc03cfca..5dc255c93e2c1d 100644
--- a/components/dashboard/src/provider-utils.tsx
+++ b/components/dashboard/src/provider-utils.tsx
@@ -29,6 +29,21 @@ function iconForAuthProvider(type: string | AuthProviderType) {
}
}
+export function toAuthProviderLabel(type: AuthProviderType) {
+ switch (type) {
+ case AuthProviderType.GITHUB:
+ return "GitHub";
+ case AuthProviderType.GITLAB:
+ return "GitLab";
+ case AuthProviderType.BITBUCKET:
+ return "Bitbucket Cloud";
+ case AuthProviderType.BITBUCKET_SERVER:
+ return "Bitbucket Server";
+ default:
+ return "Unknown type";
+ }
+}
+
function simplifyProviderName(host: string) {
switch (host) {
case "github.com":
diff --git a/components/dashboard/src/user-settings/AuthEntryItem.tsx b/components/dashboard/src/user-settings/AuthEntryItem.tsx
index d2d801faf3544c..55a52f83969d78 100644
--- a/components/dashboard/src/user-settings/AuthEntryItem.tsx
+++ b/components/dashboard/src/user-settings/AuthEntryItem.tsx
@@ -4,17 +4,17 @@
* See License.AGPL.txt in the project root for license information.
*/
-import { AuthProviderInfo } from "@gitpod/gitpod-protocol";
import { useState } from "react";
import { ContextMenuEntry } from "../components/ContextMenu";
import { Item, ItemFieldIcon, ItemField, ItemFieldContextMenu } from "../components/ItemsList";
+import { AuthProviderDescription } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
interface AuthEntryItemParams {
- ap: AuthProviderInfo;
+ ap: AuthProviderDescription;
isConnected: (authProviderId: string) => boolean;
getUsername: (authProviderId: string) => string | undefined;
getPermissions: (authProviderId: string) => string[] | undefined;
- gitProviderMenu: (provider: AuthProviderInfo) => ContextMenuEntry[];
+ gitProviderMenu: (provider: AuthProviderDescription) => ContextMenuEntry[];
}
export const AuthEntryItem = (props: AuthEntryItemParams) => {
@@ -25,32 +25,32 @@ export const AuthEntryItem = (props: AuthEntryItemParams) => {
};
return (
- -
+
-
- {props.ap.authProviderType}
+ {props.ap.type}
{props.ap.host}
- {props.getUsername(props.ap.authProviderId) || "–"}
+ {props.getUsername(props.ap.id) || "–"}
Username
- {props.getPermissions(props.ap.authProviderId)?.join(", ") || "–"}
+ {props.getPermissions(props.ap.id)?.join(", ") || "–"}
Permissions
diff --git a/components/dashboard/src/user-settings/Integrations.tsx b/components/dashboard/src/user-settings/Integrations.tsx
index 24a8700ba11991..bd196a0def60b7 100644
--- a/components/dashboard/src/user-settings/Integrations.tsx
+++ b/components/dashboard/src/user-settings/Integrations.tsx
@@ -4,12 +4,12 @@
* See License.AGPL.txt in the project root for license information.
*/
-import { AuthProviderEntry, AuthProviderInfo, User } from "@gitpod/gitpod-protocol";
+import { AuthProviderEntry, User } from "@gitpod/gitpod-protocol";
import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth";
import { useQuery } from "@tanstack/react-query";
import React, { useCallback, useContext, useEffect, useState } from "react";
import Alert from "../components/Alert";
-import { CheckboxInputField, CheckboxListField } from "../components/forms/CheckboxInputField";
+import { CheckboxListField } from "../components/forms/CheckboxInputField";
import ConfirmationModal from "../components/ConfirmationModal";
import { ContextMenuEntry } from "../components/ContextMenu";
import { Delayed } from "../components/Delayed";
@@ -20,16 +20,17 @@ import Modal, { ModalBody, ModalHeader, ModalFooter } from "../components/Modal"
import { Heading2, Subheading } from "../components/typography/headings";
import copy from "../images/copy.svg";
import exclamation from "../images/exclamation.svg";
-import { openAuthorizeWindow } from "../provider-utils";
+import { openAuthorizeWindow, toAuthProviderLabel } from "../provider-utils";
import { getGitpodService, gitpodHostUrl } from "../service/service";
import { UserContext } from "../user-context";
import { AuthEntryItem } from "./AuthEntryItem";
import { IntegrationEntryItem } from "./IntegrationItemEntry";
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu";
import { SelectAccountModal } from "./SelectAccountModal";
-import { useAuthProviders } from "../data/auth-providers/auth-provider-query";
+import { useAuthProviderDescriptions } from "../data/auth-providers/auth-provider-query";
import { useFeatureFlag } from "../data/featureflag-query";
import { EmptyMessage } from "../components/EmptyMessage";
+import { AuthProviderDescription } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
export default function Integrations() {
return (
@@ -46,11 +47,13 @@ export default function Integrations() {
function GitProviders() {
const { user, setUser } = useContext(UserContext);
- const authProviders = useAuthProviders();
+ const authProviders = useAuthProviderDescriptions();
const [allScopes, setAllScopes] = useState