From 21bb3c1d550d168bfa52bb04eb1dfed3b83775fb Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Thu, 16 Nov 2023 16:53:54 +0100 Subject: [PATCH] =?UTF-8?q?Use=20AuthProviderService=20API=20in=20Dashboar?= =?UTF-8?q?d=20=E2=80=93=20EXP-847=20(#19057)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * convert Login.ts * extract auth provider utils into protocol * complete migration from useAuthProviders to useAuthProviderDescriptions * fixup import of scopes util * revert rename * migrate useDeleteOrgAuthProviderMutation * migrate Org Git Integrations * fix label for authprovider types * wip migration user-level git integrations * WIP updateProviderEntry * wip migration * fixup: label of auth provider types * fixup: dont render Unknown type * fix label * fix this undefined * bump CACHE_VERSION * fixup allow to change the `clientId` only * fixup add AuthProviderClasses to supported messages --------- Co-authored-by: Huiwen --- components/dashboard/src/Login.tsx | 12 +- .../dashboard/src/components/AuthorizeGit.tsx | 23 +- .../src/components/RepositoryFinder.tsx | 10 +- .../auth-provider-descriptions-query.ts | 34 +++ .../auth-providers/auth-provider-query.ts | 18 -- .../create-org-auth-provider-mutation.ts | 46 ++++ .../create-user-auth-provider-mutation.ts | 46 ++++ .../delete-org-auth-provider-mutation.ts | 18 +- .../delete-user-auth-provider-mutation.ts | 47 ++++ .../auth-providers/get-auth-provider-query.ts | 26 ++ .../org-auth-providers-query.ts | 20 +- .../update-org-auth-provider-mutation.ts | 42 ++++ .../update-user-auth-provider-mutation.ts | 42 ++++ .../upsert-org-auth-provider-mutation.ts | 34 --- .../user-auth-providers-query.ts | 38 +++ .../src/data/git-providers/github-queries.ts | 7 +- .../provider-repositories-query.ts | 7 +- components/dashboard/src/data/setup.tsx | 4 +- .../dashboard/src/projects/NewProject.tsx | 38 ++- .../new-project/NewProjectAuthRequired.tsx | 10 +- .../new-project/NewProjectRepoSelection.tsx | 7 +- components/dashboard/src/provider-utils.tsx | 22 +- .../service/json-rpc-authprovider-client.ts | 8 +- .../GitIntegrationListItem.tsx | 15 +- .../git-integrations/GitIntegrationModal.tsx | 146 +++++++----- .../git-integrations/GitIntegrationsList.tsx | 4 +- .../src/user-settings/AuthEntryItem.tsx | 19 +- .../user-settings/IntegrationItemEntry.tsx | 11 +- .../src/user-settings/Integrations.tsx | 225 +++++++++++------- .../src/workspaces/CreateWorkspacePage.tsx | 12 +- .../gitpod-protocol/src/auth-providers.ts | 131 ++++++++++ components/gitpod-protocol/src/index.ts | 1 + .../server/src/auth/auth-provider-service.ts | 8 +- 33 files changed, 827 insertions(+), 304 deletions(-) create mode 100644 components/dashboard/src/data/auth-providers/auth-provider-descriptions-query.ts delete mode 100644 components/dashboard/src/data/auth-providers/auth-provider-query.ts create mode 100644 components/dashboard/src/data/auth-providers/create-org-auth-provider-mutation.ts create mode 100644 components/dashboard/src/data/auth-providers/create-user-auth-provider-mutation.ts create mode 100644 components/dashboard/src/data/auth-providers/delete-user-auth-provider-mutation.ts create mode 100644 components/dashboard/src/data/auth-providers/get-auth-provider-query.ts create mode 100644 components/dashboard/src/data/auth-providers/update-org-auth-provider-mutation.ts create mode 100644 components/dashboard/src/data/auth-providers/update-user-auth-provider-mutation.ts delete mode 100644 components/dashboard/src/data/auth-providers/upsert-org-auth-provider-mutation.ts create mode 100644 components/dashboard/src/data/auth-providers/user-auth-providers-query.ts create mode 100644 components/gitpod-protocol/src/auth-providers.ts diff --git a/components/dashboard/src/Login.tsx b/components/dashboard/src/Login.tsx index 3990df02bf041e..fb7c2a41142b37 100644 --- a/components/dashboard/src/Login.tsx +++ b/components/dashboard/src/Login.tsx @@ -4,7 +4,6 @@ * See License.AGPL.txt in the project root for license information. */ -import { AuthProviderInfo } from "@gitpod/gitpod-protocol"; import * as GitpodCookie from "@gitpod/gitpod-protocol/lib/util/gitpod-cookie"; import { useContext, useEffect, useState, useMemo, useCallback, FC } from "react"; import { UserContext } from "./user-context"; @@ -18,9 +17,10 @@ import { getURLHash } from "./utils"; import ErrorMessage from "./components/ErrorMessage"; import { Heading1, Heading2, Subheading } from "./components/typography/headings"; import { SSOLoginForm } from "./login/SSOLoginForm"; -import { useAuthProviders } from "./data/auth-providers/auth-provider-query"; +import { useAuthProviderDescriptions } from "./data/auth-providers/auth-provider-descriptions-query"; import { SetupPending } from "./login/SetupPending"; import { useNeedsSetup } from "./dedicated-setup/use-needs-setup"; +import { AuthProviderDescription } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb"; export function markLoggedIn() { document.cookie = GitpodCookie.generateCookie(window.location.hostname); @@ -38,7 +38,7 @@ export const Login: FC = ({ onLoggedIn }) => { const urlHash = useMemo(() => getURLHash(), []); - const authProviders = useAuthProviders(); + const authProviders = useAuthProviderDescriptions(); const [errorMessage, setErrorMessage] = useState(undefined); const [hostFromContext, setHostFromContext] = useState(); const [repoPathname, setRepoPathname] = useState(); @@ -58,7 +58,7 @@ export const Login: FC = ({ onLoggedIn }) => { } }, [urlHash]); - let providerFromContext: AuthProviderInfo | undefined; + let providerFromContext: AuthProviderDescription | undefined; if (hostFromContext && authProviders.data) { providerFromContext = authProviders.data.find((provider) => provider.host === hostFromContext); } @@ -158,7 +158,7 @@ export const Login: FC = ({ onLoggedIn }) => { className="btn-login flex-none w-56 h-10 p-0 inline-flex rounded-xl" onClick={() => openLogin(providerFromContext!.host)} > - {iconForAuthProvider(providerFromContext.authProviderType)} + {iconForAuthProvider(providerFromContext.type)} Continue with {simplifyProviderName(providerFromContext.host)} @@ -170,7 +170,7 @@ export const Login: FC = ({ onLoggedIn }) => { className="btn-login flex-none w-56 h-10 p-0 inline-flex rounded-xl" onClick={() => openLogin(ap.host)} > - {iconForAuthProvider(ap.authProviderType)} + {iconForAuthProvider(ap.type)} Continue with {simplifyProviderName(ap.host)} diff --git a/components/dashboard/src/components/AuthorizeGit.tsx b/components/dashboard/src/components/AuthorizeGit.tsx index 96e945b1aa8cd9..aa8ad0c0cd1640 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-descriptions-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 { data: 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, }); @@ -46,15 +45,13 @@ export const AuthorizeGit: FC<{ className?: string }> = ({ className }) => { [updateUser], ); - if (authProviders.data === undefined) { + if (authProviders === undefined) { return <>; } - const verifiedProviders = authProviders.data.filter((ap) => ap.verified); - return (
- {verifiedProviders.length === 0 ? ( + {authProviders.length === 0 ? ( <> No Git integrations {!!owner ? ( @@ -82,7 +79,7 @@ export const AuthorizeGit: FC<{ className?: string }> = ({ className }) => { Select one of the following available providers to access repositories for your account.
- {verifiedProviders.map((ap) => { + {authProviders.map((ap) => { return (