feat: add OAuth client developer settings page with approval workflow (#25556)

* feat: add OAuth client developer settings page with approval workflow

- Add new developer OAuth page at /settings/developer/oAuth for users to submit OAuth client requests
- Transform admin OAuth page into management dashboard for reviewing/approving submissions
- Add OAuthClientApprovalStatus enum (PENDING, APPROVED, REJECTED) to track submission status
- Add userId and createdAt fields to OAuthClient model for tracking submissions
- Create email notifications for admin (new submission) and user (approval)
- Add sidebar navigation link in developer section below API keys
- Add comprehensive translations for new UI strings
- Create OAuthClientRepository for data access following repository pattern

Co-Authored-By: [email protected] <[email protected]>

* fix: re-export generateSecret for backward compatibility

Co-Authored-By: [email protected] <[email protected]>

* feat: make logo mandatory and list items clickable for OAuth clients

Co-Authored-By: [email protected] <[email protected]>

* fix: add missing translation keys and remove client secret from details dialog

Co-Authored-By: [email protected] <[email protected]>

* fix: address cubic AI reviewer comments

- Remove duplicate 'there' JSON key in common.json
- Add select clause to findByUserId to avoid exposing clientSecret
- Add @@index([userId]) to OAuthClient model for query performance
- Update migration to include the index

Co-Authored-By: [email protected] <[email protected]>

* fix: address PR review comments - fix indentation and use useCopy hook

Co-Authored-By: [email protected] <[email protected]>

* fix: change react-dom/server import to fix Turbopack compatibility

Co-Authored-By: [email protected] <[email protected]>

* Revert "fix: change react-dom/server import to fix Turbopack compatibility"

This reverts commit c3e0b709c2d88fd221143cb4ce9cd25bb8c94277.

* fix: use email service pattern for OAuth client notifications

Co-Authored-By: [email protected] <[email protected]>

* fix: add try-catch around email sending to handle Turbopack react-dom/server issue

Co-Authored-By: [email protected] <[email protected]>

* Revert "fix: add try-catch around email sending to handle Turbopack react-dom/server issue"

This reverts commit fc9d47cd773505ebc5ee2696718aad4a8a98be77.

* fix: improve OAuth client UI with skeleton loaders and smaller dialog styling

- Replace 'Loading...' text with proper skeleton loaders in both developer and admin OAuth client views
- Make client_id and copy button smaller in dialogs using size='sm' and text-sm styling
- Add 'client_id' translation key to common.json for proper i18n

Co-Authored-By: [email protected] <[email protected]>

* fix: improve skeleton loader to match actual OAuth client list structure

- Remove divide-y from container and use conditional border-b on rows
- Match the exact structure from oauth-clients-view.tsx L126-160
- Use proper spacing for text elements (mt-1 instead of space-y-2)

Co-Authored-By: [email protected] <[email protected]>

* fix skeleton

* rename the selected oauth client dialog

* fix: address PR feedback - admin auth, dropdown styling, sidebar label

- Add defense-in-depth admin authorization check in updateClientStatus handler
- Fix broken dropdown menu by using DropdownItem with StartIcon prop
- Fix sidebar menu label from 'oAuth' to 'oauth_clients' to match developer view

Co-Authored-By: [email protected] <[email protected]>

* update common.json

* feat: show client secret in approval email for confidential OAuth clients

- Add regenerateSecret method to OAuthClientRepository
- Regenerate secret when admin approves a PENDING confidential client
- Include client secret in approval notification email
- Add one-time warning message about storing the secret securely
- Only regenerate on first approval (not re-approvals)

Co-Authored-By: [email protected] <[email protected]>

* feat: add Website URL field, fix logo styling, show client secret after approval

- Add Website URL field to OAuth client forms (admin and developer views)
- Fix Upload Logo section styling by wrapping in Label div with proper gap
- Display client secret in dialog after admin approves a confidential OAuth client
- Add websiteUrl field to Prisma schema with migration
- Update tRPC handlers and repository to support websiteUrl
- Add translation keys for new UI elements

Co-Authored-By: [email protected] <[email protected]>

* fix: move clientSecret variable declaration outside if block for proper scoping

Co-Authored-By: [email protected] <[email protected]>

* refactor: dont expose client secret in emails

* refactor: dont regenerate secret upon status change

* refactor: reuse existing hash function

* refactor: rename admin/oAuth to admin/oauth page

* refactor: deduplicate oauth repositories

* refactor: remove withGlobalPrisma from oauth repository

* refactor: developer oauth page

* refactor: oauth status by default accepted

* refactor: request oauth status when creating

* refactor ux

* fix: address Cubic AI code review feedback

- Add purpose field to plain text email body for accessibility
- Convert NewOAuthClientButton to inline JSX to avoid React anti-pattern
- Trigger re-approval when redirectUri changes for security
- Add e.preventDefault() for Space key to prevent page scroll
- Change default approvalStatus to PENDING for defense-in-depth
- Use oauth_clients translation key for consistency
- Add meaningful alt text to Avatar for accessibility
- Remove onClick from DialogClose to prevent double-run close effects
- Return NOT_FOUND for non-owner delete to prevent resource enumeration

Co-Authored-By: unknown <>

* common.json file

* refactor: delete all prisma migrations

* refactor: have just 1 prisma migration

* revert: some devin changes

* fix: typecheck

* test: owner OAuth crud

* test: admin OAuth approval / rejection

* fix: address Cubic AI review feedback (confidence 9/10 issues)

- schema.prisma: Remove @default("") from purpose field to make it required
- schema.prisma: Use UTC-aware timezone expression for createdAt default
- OAuthClientFormFields.tsx: Localize redirect URI placeholder using t()
- common.json: Add redirect_uri_placeholder translation key

Co-Authored-By: unknown <>

* cubic changes

* refactor: dont log sensitive info and rethrow error

* cubic feedback

* refactor: make oauth client purpose optional

* refactor: admin/oauth not allowed if not logged in

* refactor: admin view skeleton

* refactor: rename state

* refactor: get rid of redundant mapping

* refactor: remove redundant handler

* refactor: remove redundant handler

* refactor: re-usable new oauth client button

* refactor: dialogs

* refactor: modals

* refactor: handler names, dialog, skeleton

* fix: purpose being null

* refactor: rename handler and delete old oauth admin page

* fix: purpose in submission

* refactor: handler names

* refactor: rename

* refactor: update handler

* refactor: rename approvalStatus -> status

* refactor: simplify modal

* refactor: name

* dont require repproval if redirectUri changes

* fix: remove integration sync index creation

* refactor: require re-approval if redirectUri updated

* fix: flaky e2e test

* fix: flaky e2e test

* fix: flaky e2e test

* fix: remove duplicate common.json keys

* refactor: replace [email protected] with SUPPORT_MAIL_ADDRESS

* refactor: generate client secret on handler level

* fix: authorization code only available to approved clients

* refactor: cubic review dont display exclamation

* refactor: cubic review website_url in common json

* fix: dont default in ui to approved status

* refactor: optiona logo in schema create handler

* fix: tests

* fix: tests

* fix: /authorize redirect if client not approved or show error

* test: authorize page with invalid client id

* refactor: dont allow refreshing tokens unless approved client

* fix: flaky e2e test

* fix: flaky e2e test

* fix: flaky e2e test

* fix: flaky e2e test

* fix: flaky e2e test

* fix: flaky e2e test

* chore: warn that pending client is not usable

* fix: approve and reject buttons

* fix: /authorize show error if client not approved

* refactor: info message about editing oauth client and status

* change info alert to warning

* try to fix ci test

* debug: failing e2e test

* fix: improve session propagation in oauth-client-admin E2E test

- Add navigateToAdminOAuthPage helper that waits for listClients API call
- If the API call doesn't arrive (session issue), reload page to force session refresh
- This fixes the CI flakiness where admin page wasn't loading due to session not having ADMIN role

Co-Authored-By: [email protected] <[email protected]>

* fix: register waitForResponse before navigating in E2E test

- Register the listClients waitForResponse promise BEFORE page.goto()
- This ensures the response isn't missed during page load
- Also register the promise before reload in the catch block

Co-Authored-By: [email protected] <[email protected]>

* fix: rename oAuth folder to oauth for case-sensitive filesystems

The admin OAuth page route was at /settings/admin/oAuth (capital A) but the
code references /settings/admin/oauth (lowercase). This caused 404 errors
on case-sensitive filesystems (Linux).

Also improved the E2E test navigation helper to retry with delays if the
admin page doesn't load immediately, handling session propagation timing.

Co-Authored-By: [email protected] <[email protected]>

* test style

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Lauris Skraucis <[email protected]>
Co-authored-by: supalarry <[email protected]>
Co-authored-by: cubic-dev-ai[bot] <1082092+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Morgan <[email protected]>
This commit is contained in:
60 files changed
+5231 -368

No files matched your search

@@ -0,0 +1,42 @@
"use client";
import { SkeletonText, SkeletonContainer } from "@calcom/ui/components/skeleton";
export const OAuthClientsAdminSkeleton = () => {
return (
<SkeletonContainer>
<div className="mb-8">
<SkeletonText className="h-7 w-64" />
<div className="mt-2 flex items-start justify-between gap-4">
<SkeletonText className="h-4 w-full max-w-xl" />
<div className="bg-emphasis h-9 w-20 rounded-md" />
</div>
</div>
<div className="space-y-10">
{[1, 2, 3].map((section) => (
<div key={section} className="space-y-3">
<SkeletonText className="h-5 w-24" />
<div className="border-subtle rounded-lg border">
{[1, 2, 3].map((row) => (
<div
// eslint-disable-next-line react/no-array-index-key
key={`${section}-${row}`}
className={`flex items-center justify-between p-4 ${row !== 3 ? "border-subtle border-b" : ""}`}>
<div className="flex items-center gap-4">
<div className="bg-emphasis h-10 w-10 rounded-full" />
<SkeletonText className="h-4 w-40" />
</div>
<div className="flex items-center gap-4">
<SkeletonText className="h-5 w-20 rounded-full" />
<div className="bg-emphasis h-5 w-5 rounded" />
</div>
</div>
))}
</div>
</div>
))}
</div>
</SkeletonContainer>
);
};
@@ -0,0 +1,196 @@
"use client";
import { useState } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { OAuthClientsAdminSkeleton } from "./oauth-clients-admin-skeleton";
import { EmptyScreen } from "@calcom/ui/components/empty-screen";
import { showToast } from "@calcom/ui/components/toast";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import type { OAuthClientCreateFormValues } from "../oauth/create/OAuthClientCreateModal";
import { OAuthClientCreateDialog } from "../oauth/create/OAuthClientCreateModal";
import { OAuthClientPreviewDialog } from "../oauth/create/OAuthClientPreviewDialog";
import { OAuthClientDetailsDialog, type OAuthClientDetails } from "../oauth/view/OAuthClientDetailsDialog";
import { OAuthClientsList } from "../oauth/OAuthClientsList";
import { NewOAuthClientButton } from "../oauth/create/NewOAuthClientButton";
export default function OAuthClientsAdminView() {
const { t } = useLocale();
const utils = trpc.useUtils();
const [isCreatingClient, setIsCreatingClient] = useState(false);
const [createdClient, setCreatedClient] = useState<OAuthClientDetails | null>(null);
const [selectedClient, setSelectedClient] = useState<OAuthClientDetails | null>(null);
const { data: pendingClients, isLoading: isPendingClientsLoading } = trpc.viewer.oAuth.listClients.useQuery({
status: "PENDING",
});
const { data: rejectedClients, isLoading: isRejectedClientsLoading } = trpc.viewer.oAuth.listClients.useQuery({
status: "REJECTED",
});
const { data: approvedClients, isLoading: isApprovedClientsLoading } = trpc.viewer.oAuth.listClients.useQuery({
status: "APPROVED",
});
const createMutation = trpc.viewer.oAuth.createClient.useMutation({
onSuccess: async (data) => {
setCreatedClient({
clientId: data.clientId,
clientSecret: data.clientSecret,
name: data.name,
purpose: data.purpose ?? "",
status: data.status,
redirectUri: data.redirectUri,
logo: data.logo || null,
});
showToast(t("oauth_client_created"), "success");
utils.viewer.oAuth.listClients.invalidate();
},
onError: (error) => {
showToast(`${t("oauth_client_create_error")}: ${error.message}`, "error");
},
});
const updateStatusMutation = trpc.viewer.oAuth.updateClient.useMutation({
onSuccess: async (data) => {
showToast(
t("oauth_client_status_updated", { name: data.name, status: data.status }),
"success"
);
setSelectedClient((prev) => {
if (!prev) return prev;
if (prev.clientId !== data.clientId) return prev;
return {
...prev,
status: data.status,
rejectionReason: data.rejectionReason,
};
});
utils.viewer.oAuth.listClients.invalidate();
},
onError: (error) => {
showToast(`${t("oauth_client_status_update_error")}: ${error.message}`, "error");
},
});
const handleCreateClient = (values: OAuthClientCreateFormValues) => {
createMutation.mutate({
name: values.name,
purpose: values.purpose,
redirectUri: values.redirectUri,
websiteUrl: values.websiteUrl,
logo: values.logo,
enablePkce: values.enablePkce,
});
};
const handleCloseDialog = () => {
setIsCreatingClient(false);
setCreatedClient(null);
};
const handleCloseClientDialog = () => {
setSelectedClient(null);
};
const handleApprove = (clientId: string) => {
updateStatusMutation.mutate({ clientId, status: "APPROVED" });
};
const handleReject = (input: { clientId: string; rejectionReason: string }) => {
updateStatusMutation.mutate({ clientId: input.clientId, status: "REJECTED", rejectionReason: input.rejectionReason });
};
if (isPendingClientsLoading || isRejectedClientsLoading || isApprovedClientsLoading) {
return <OAuthClientsAdminSkeleton />;
}
const newOAuthClientButton = (
<NewOAuthClientButton
dataTestId="open-admin-oauth-client-create-dialog"
onClick={() => setIsCreatingClient(true)}
/>
);
const hasClients =
(pendingClients && pendingClients.length > 0) ||
(rejectedClients && rejectedClients.length > 0) ||
(approvedClients && approvedClients.length > 0);
return (
<SettingsHeader
title={t("oauth_clients_admin")}
description={t("oauth_clients_admin_description")}
CTA={newOAuthClientButton}>
{hasClients ? (
<div className="space-y-10">
<div className="space-y-3" data-testid="oauth-client-admin-pending-section">
<h2 className="text-emphasis text-base font-semibold">{t("pending")}</h2>
<OAuthClientsList
clients={pendingClients ?? []}
onSelectClient={(client) => setSelectedClient(client)}
showStatus
/>
</div>
<div className="space-y-3" data-testid="oauth-client-admin-rejected-section">
<h2 className="text-emphasis text-base font-semibold">{t("rejected")}</h2>
<OAuthClientsList
clients={rejectedClients ?? []}
onSelectClient={(client) => setSelectedClient(client)}
showStatus
/>
</div>
<div className="space-y-3" data-testid="oauth-client-admin-approved-section">
<h2 className="text-emphasis text-base font-semibold">{t("approved")}</h2>
<OAuthClientsList
clients={approvedClients ?? []}
onSelectClient={(client) => setSelectedClient(client)}
showStatus
/>
</div>
</div>
) : (
<EmptyScreen
Icon="key"
headline={t("no_oauth_clients")}
description={t("no_oauth_clients_admin_description")}
buttonRaw={newOAuthClientButton}
/>
)}
{createdClient ? (
<OAuthClientPreviewDialog
open={isCreatingClient}
onOpenChange={setIsCreatingClient}
title={t("oauth_client_created")}
description={t("oauth_client_created_description")}
client={createdClient}
onClose={handleCloseDialog}
/>
) : (
<OAuthClientCreateDialog
open={isCreatingClient}
onOpenChange={setIsCreatingClient}
isSubmitting={createMutation.isPending}
onSubmit={handleCreateClient}
onClose={handleCloseDialog}
/>
)}
<OAuthClientDetailsDialog
open={Boolean(selectedClient)}
onOpenChange={(open) => !open && handleCloseClientDialog()}
client={selectedClient}
onApprove={handleApprove}
onReject={handleReject}
isStatusChangePending={updateStatusMutation.isPending}
/>
</SettingsHeader>
);
}
@@ -1,180 +0,0 @@
"use client";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { Avatar } from "@calcom/ui/components/avatar";
import { Button } from "@calcom/ui/components/button";
import { Form } from "@calcom/ui/components/form";
import { Label } from "@calcom/ui/components/form";
import { Switch } from "@calcom/ui/components/form";
import { TextField } from "@calcom/ui/components/form";
import { Icon } from "@calcom/ui/components/icon";
import { ImageUploader } from "@calcom/ui/components/image-uploader";
import { showToast } from "@calcom/ui/components/toast";
import { Tooltip } from "@calcom/ui/components/tooltip";
type FormValues = {
name: string;
redirectUri: string;
logo: string;
enablePkce: boolean;
};
export default function OAuthView() {
const oAuthForm = useForm<FormValues>({
defaultValues: {
logo: "",
enablePkce: false,
},
});
const [clientSecret, setClientSecret] = useState("");
const [clientId, setClientId] = useState("");
const [logo, setLogo] = useState("");
const { t } = useLocale();
const mutation = trpc.viewer.oAuth.addClient.useMutation({
onSuccess: async (data) => {
setClientSecret(data.clientSecret || "");
setClientId(data.clientId);
showToast(`Successfully added ${data.name} as new client`, "success");
},
onError: (error) => {
showToast(`Adding client failed: ${error.message}`, "error");
},
});
return (
<div>
{!clientId ? (
<Form
form={oAuthForm}
handleSubmit={(values) => {
mutation.mutate({
name: values.name,
redirectUri: values.redirectUri,
logo: values.logo,
enablePkce: values.enablePkce,
});
}}>
<div className="">
<TextField
{...oAuthForm.register("name")}
label="Client name"
type="text"
id="name"
placeholder=""
className="mb-3"
required
/>
<TextField
{...oAuthForm.register("redirectUri")}
label="Redirect URI"
type="text"
id="redirectUri"
placeholder=""
required
/>
<div className="mb-5 mt-5">
<Label className="text-emphasis mb-2 block text-sm font-medium">Authentication Mode</Label>
<div className="flex items-center space-x-3">
<Switch
checked={oAuthForm.watch("enablePkce")}
onCheckedChange={(checked) => oAuthForm.setValue("enablePkce", checked)}
/>
<span className="text-default text-sm">
Use PKCE (recommended for mobile/SPA applications)
</span>
</div>
</div>
<div className="mb-5 mt-5 flex items-center">
<Avatar
alt=""
fallback={<Icon name="plus" className="text-subtle h-6 w-6" />}
className="mr-5 items-center"
imageSrc={logo}
size="lg"
/>
<ImageUploader
target="avatar"
id="avatar-upload"
buttonMsg="Upload Logo"
handleAvatarChange={(newLogo: string) => {
setLogo(newLogo);
oAuthForm.setValue("logo", newLogo);
}}
imageSrc={logo}
/>
</div>
</div>
<Button type="submit" className="mt-3">
{t("add_client")}
</Button>
</Form>
) : (
<div>
<div className="text-emphasis mb-5 text-xl font-semibold">{oAuthForm.getValues("name")}</div>
<div className="mb-2 font-medium">{t("client_id")}</div>
<div className="flex">
<code className="bg-subtle text-default w-full truncate rounded-md rounded-r-none py-[6px] pl-2 pr-2 align-middle font-mono">
{clientId}
</code>
<Tooltip side="top" content="Copy to Clipboard">
<Button
onClick={() => {
navigator.clipboard.writeText(clientId);
showToast(t("client_id_copied"), "success");
}}
type="button"
className="rounded-l-none text-base"
StartIcon="clipboard">
{t("copy")}
</Button>
</Tooltip>
</div>
{clientSecret ? (
<>
<div className="mb-2 mt-4 font-medium">{t("client_secret")}</div>
<div className="flex">
<code className="bg-subtle text-default w-full truncate rounded-md rounded-r-none py-[6px] pl-2 pr-2 align-middle font-mono">
{clientSecret}
</code>
<Tooltip side="top" content="Copy to Clipboard">
<Button
onClick={() => {
navigator.clipboard.writeText(clientSecret);
setClientSecret("");
showToast(t("client_secret_copied"), "success");
}}
type="button"
className="rounded-l-none text-base"
StartIcon="clipboard">
{t("copy")}
</Button>
</Tooltip>
</div>
<div className="text-subtle text-sm">{t("copy_client_secret_info")}</div>
</>
) : (
<div className="text-subtle mt-4 text-sm">
This client uses PKCE authentication (no client secret required).
</div>
)}
<Button
onClick={() => {
setClientId("");
setLogo("");
oAuthForm.reset();
}}
className="mt-5">
{t("add_new_client")}
</Button>
</div>
)}
</div>
);
}
@@ -0,0 +1,37 @@
"use client";
import { SkeletonText, SkeletonContainer } from "@calcom/ui/components/skeleton";
const skeletonItems = Array(3).fill(undefined);
export const OAuthClientsSkeleton = () => {
return (
<SkeletonContainer>
<div className="mb-8">
<SkeletonText className="h-7 w-64" />
<div className="mt-2 flex items-start justify-between gap-4">
<SkeletonText className="h-4 w-full max-w-xl" />
<div className="bg-emphasis h-9 w-20 rounded-md" />
</div>
</div>
<div className="border-subtle rounded-lg border">
{skeletonItems.map((i, index) => (
<div
key={`oauth-client-skeleton-${index}`}
className={`flex items-center justify-between p-4 ${
index !== skeletonItems.length - 1 ? "border-subtle border-b" : ""
}`}>
<div className="flex items-center gap-4">
<div className="bg-emphasis h-10 w-10 rounded-full" />
<SkeletonText className="h-4 w-40" />
</div>
<div className="flex items-center gap-4">
<SkeletonText className="h-5 w-20 rounded-full" />
<div className="bg-emphasis h-5 w-5 rounded" />
</div>
</div>
))}
</div>
</SkeletonContainer>
);
};
@@ -0,0 +1,183 @@
"use client";
import { useState } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { EmptyScreen } from "@calcom/ui/components/empty-screen";
import { showToast } from "@calcom/ui/components/toast";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import type { OAuthClientCreateFormValues } from "../oauth/create/OAuthClientCreateModal";
import { OAuthClientCreateDialog } from "../oauth/create/OAuthClientCreateModal";
import { OAuthClientPreviewDialog } from "../oauth/create/OAuthClientPreviewDialog";
import { OAuthClientDetailsDialog, type OAuthClientDetails } from "../oauth/view/OAuthClientDetailsDialog";
import { OAuthClientsList } from "../oauth/OAuthClientsList";
import { NewOAuthClientButton } from "../oauth/create/NewOAuthClientButton";
import { OAuthClientsSkeleton } from "./oauth-clients-skeleton";
const OAuthClientsView = () => {
const { t } = useLocale();
const utils = trpc.useUtils();
const [isCreatingClient, setIsCreatingClient] = useState(false);
const [submittedClient, setSubmittedClient] = useState<OAuthClientDetails | null>(null);
const [selectedClient, setSelectedClient] = useState<OAuthClientDetails | null>(null);
const { data: oAuthClients, isLoading } = trpc.viewer.oAuth.listUserClients.useQuery();
const submitForReviewMutation = trpc.viewer.oAuth.submitClientForReview.useMutation({
onSuccess: async (data) => {
setSubmittedClient({
clientId: data.clientId,
name: data.name,
purpose: data.purpose ?? "",
clientSecret: data.clientSecret,
status: data.status,
isPkceEnabled: data.isPkceEnabled,
});
showToast(t("oauth_client_submitted"), "success");
utils.viewer.oAuth.listUserClients.invalidate();
},
onError: (error) => {
showToast(`${t("oauth_client_submit_error")}: ${error.message}`, "error");
},
});
const deleteClientMutation = trpc.viewer.oAuth.deleteClient.useMutation({
onSuccess: async () => {
showToast(t("oauth_client_deletion_message"), "success");
setSelectedClient(null);
utils.viewer.oAuth.listUserClients.invalidate();
},
onError: (error) => {
showToast(error.message || t("error"), "error");
},
});
const updateClientMutation = trpc.viewer.oAuth.updateClient.useMutation({
onSuccess: async (data) => {
showToast(t("oauth_client_updated_successfully"), "success");
setSelectedClient((prev) => {
if (!prev) return prev;
if (prev.clientId !== data.clientId) return prev;
return {
...prev,
name: data.name,
purpose: data.purpose,
redirectUri: data.redirectUri,
websiteUrl: data.websiteUrl,
logo: data.logo,
status: data.status,
rejectionReason: data.rejectionReason,
};
});
utils.viewer.oAuth.listUserClients.invalidate();
},
onError: (error) => {
showToast(`${t("updating_oauth_client_error")}: ${error.message}`, "error");
},
});
const handleSubmit = (values: OAuthClientCreateFormValues) => {
submitForReviewMutation.mutate({
name: values.name,
purpose: values.purpose,
redirectUri: values.redirectUri,
websiteUrl: values.websiteUrl,
logo: values.logo,
enablePkce: values.enablePkce,
});
};
const handleCloseCreateDialog = () => {
setIsCreatingClient(false);
setSubmittedClient(null);
};
const handleCloseDetailsDialog = () => {
setSelectedClient(null);
};
if (isLoading) {
return <OAuthClientsSkeleton />;
}
const newOAuthClientButton = (
<NewOAuthClientButton dataTestId="open-oauth-client-create-dialog" onClick={() => setIsCreatingClient(true)} />
);
return (
<SettingsHeader
title={t("oauth_clients")}
description={t("oauth_clients_description")}
CTA={newOAuthClientButton}>
{oAuthClients && oAuthClients.length > 0 ? (
<OAuthClientsList
clients={oAuthClients.map((client) => ({
clientId: client.clientId,
name: client.name,
purpose: client.purpose,
redirectUri: client.redirectUri,
websiteUrl: client.websiteUrl,
logo: client.logo,
status: client.status,
rejectionReason: client.rejectionReason,
clientType: client.clientType,
}))}
onSelectClient={(client) => setSelectedClient(client)}
/>
) : (
<EmptyScreen
Icon="key"
headline={t("no_oauth_clients")}
description={t("no_oauth_clients_description")}
buttonRaw={newOAuthClientButton}
/>
)}
{submittedClient ? (
<OAuthClientPreviewDialog
open={isCreatingClient}
onOpenChange={setIsCreatingClient}
title={t("oauth_client_submitted")}
description={t("oauth_client_submitted_description")}
client={submittedClient}
onClose={handleCloseCreateDialog}
/>
) : (
<OAuthClientCreateDialog
open={isCreatingClient}
onOpenChange={setIsCreatingClient}
isSubmitting={submitForReviewMutation.isPending}
onSubmit={handleSubmit}
onClose={handleCloseCreateDialog}
/>
)}
<OAuthClientDetailsDialog
open={Boolean(selectedClient)}
onOpenChange={(open) => !open && handleCloseDetailsDialog()}
client={selectedClient}
onUpdate={(values) => {
updateClientMutation.mutate({
clientId: values.clientId,
name: values.name,
purpose: values.purpose,
redirectUri: values.redirectUri,
websiteUrl: values.websiteUrl,
logo: values.logo,
});
}}
onDelete={(clientId) => {
deleteClientMutation.mutate({ clientId });
}}
isUpdatePending={updateClientMutation.isPending}
isDeletePending={deleteClientMutation.isPending}
/>
</SettingsHeader>
);
};
export default OAuthClientsView;
@@ -0,0 +1,73 @@
"use client";
import type { ReactNode } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Avatar } from "@calcom/ui/components/avatar";
import { Badge } from "@calcom/ui/components/badge";
import { Icon } from "@calcom/ui/components/icon";
import type { OAuthClientDetails } from "./view/OAuthClientDetailsDialog";
const getStatusBadge = (status: string, t: (key: string) => string): ReactNode => {
switch (status) {
case "APPROVED":
return <Badge variant="success">{t("approved")}</Badge>;
case "REJECTED":
return <Badge variant="red">{t("rejected")}</Badge>;
case "PENDING":
default:
return <Badge variant="orange">{t("pending")}</Badge>;
}
};
export const OAuthClientsList = ({
clients,
onSelectClient,
showStatus = true,
}: {
clients: OAuthClientDetails[];
onSelectClient: (client: OAuthClientDetails) => void;
showStatus?: boolean;
}) => {
const { t } = useLocale();
return (
<div className="border-subtle rounded-lg border" data-testid="oauth-clients-list">
{clients.map((client, index) => (
<div
key={client.clientId}
data-testid={`oauth-client-list-item-${client.clientId}`}
className={`hover:bg-subtle flex cursor-pointer items-center justify-between p-4 transition-colors ${
index !== clients.length - 1 ? "border-subtle border-b" : ""
}`}
onClick={() => onSelectClient(client)}
role="button"
tabIndex={0}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
onSelectClient(client);
}
}}>
<div className="flex items-center gap-4">
<Avatar
alt={client.name}
imageSrc={client.logo || undefined}
fallback={<Icon name="key" className="text-subtle h-6 w-6" />}
size="md"
/>
<div>
<div className="text-emphasis font-medium">{client.name}</div>
</div>
</div>
<div className="flex items-center gap-4">
{showStatus && client.status ? getStatusBadge(client.status, t) : null}
<Icon name="chevron-right" className="text-subtle h-5 w-5" />
</div>
</div>
))}
</div>
);
};
@@ -0,0 +1,20 @@
"use client";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Button } from "@calcom/ui/components/button";
export const NewOAuthClientButton = ({
onClick,
dataTestId,
}: {
onClick: () => void;
dataTestId: string;
}) => {
const { t } = useLocale();
return (
<Button color="secondary" StartIcon="plus" size="sm" variant="fab" data-testid={dataTestId} onClick={onClick}>
{t("new")}
</Button>
);
};
@@ -0,0 +1,102 @@
"use client";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { OAuthClientFormFields } from "../view/OAuthClientFormFields";
import { Dialog } from "@calcom/features/components/controlled-dialog";
import { Button } from "@calcom/ui/components/button";
import { DialogClose, DialogContent, DialogFooter } from "@calcom/ui/components/dialog";
import { Form } from "@calcom/ui/components/form";
export type OAuthClientCreateFormValues = {
name: string;
purpose: string;
redirectUri: string;
websiteUrl: string;
logo: string;
enablePkce: boolean;
};
export type OAuthClientCreateDialogProps = {
open: boolean;
onOpenChange: (open: boolean) => void;
isSubmitting: boolean;
onSubmit: (values: OAuthClientCreateFormValues) => void;
onClose: () => void;
};
export function OAuthClientCreateDialog({
open,
onOpenChange,
isSubmitting,
onSubmit,
onClose,
}: OAuthClientCreateDialogProps) {
const { t } = useLocale();
const [logo, setLogo] = useState("");
const form = useForm<OAuthClientCreateFormValues>({
defaultValues: {
name: "",
purpose: "",
redirectUri: "",
websiteUrl: "",
logo: "",
enablePkce: false,
},
});
const handleClose = () => {
onClose();
setLogo("");
form.reset();
};
const handleOpenChange = (nextOpen: boolean) => {
if (!nextOpen) {
handleClose();
return;
}
onOpenChange(nextOpen);
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent
enableOverflow
type="creation"
title={t("create_oauth_client")}
description={t("create_oauth_client_description")}>
<Form
form={form}
handleSubmit={(values) => {
onSubmit({
name: values.name.trim() || "",
purpose: values.purpose.trim() || "",
redirectUri: values.redirectUri.trim() || "",
websiteUrl: values.websiteUrl.trim() || "",
logo: values.logo,
enablePkce: values.enablePkce,
});
}}
className="space-y-4"
data-testid="oauth-client-create-form">
<OAuthClientFormFields form={form} logo={logo} setLogo={setLogo} />
<DialogFooter>
<DialogClose>{t("close")}</DialogClose>
<Button type="submit" loading={isSubmitting} data-testid="oauth-client-create-submit">
{t("create")}
</Button>
</DialogFooter>
</Form>
</DialogContent>
</Dialog>
);
}
@@ -0,0 +1,130 @@
"use client";
import { useCopy } from "@calcom/lib/hooks/useCopy";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Dialog } from "@calcom/features/components/controlled-dialog";
import { Alert } from "@calcom/ui/components/alert";
import { Badge } from "@calcom/ui/components/badge";
import { Button } from "@calcom/ui/components/button";
import { DialogContent, DialogFooter } from "@calcom/ui/components/dialog";
import { showToast } from "@calcom/ui/components/toast";
import { Tooltip } from "@calcom/ui/components/tooltip";
import type { OAuthClientDetails } from "../view/OAuthClientDetailsDialog";
export function OAuthClientPreviewDialog({
open,
onOpenChange,
title,
description,
client,
onClose,
}: {
open: boolean;
onOpenChange: (open: boolean) => void;
title: string;
description: string;
client: OAuthClientDetails;
onClose: () => void;
}) {
const { t } = useLocale();
const { copyToClipboard } = useCopy();
const handleOpenChange = (nextOpen: boolean) => {
if (!nextOpen) {
onClose();
return;
}
onOpenChange(nextOpen);
};
const showPendingBadge = client.status === "PENDING";
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent enableOverflow type="creation" title={title} description={description}>
<>
<div className="space-y-4" data-testid="oauth-client-submitted-modal">
{showPendingBadge ? (
<div className="flex items-center justify-start">
<Badge variant="orange">{t("pending")}</Badge>
</div>
) : null}
<div>
<div className="text-subtle mb-1 text-sm">{t("client_name")}</div>
<div className="text-emphasis font-medium">{client.name}</div>
</div>
<div>
<div className="text-subtle mb-1 text-sm">{t("client_id")}</div>
<div className="flex">
<code
data-testid="oauth-client-submitted-client-id"
className="bg-subtle text-default w-full truncate rounded-md rounded-r-none px-2 py-1 align-middle font-mono text-sm">
{client.clientId}
</code>
<Tooltip side="top" content={t("copy_to_clipboard")}>
<Button
onClick={() => {
copyToClipboard(client.clientId, {
onSuccess: () => showToast(t("client_id_copied"), "success"),
onFailure: () => showToast(t("error"), "error"),
});
}}
type="button"
size="sm"
className="rounded-l-none"
StartIcon="clipboard">
{t("copy")}
</Button>
</Tooltip>
</div>
</div>
{client.clientSecret ? (
<div>
<div className="text-subtle mb-1 text-sm">{t("client_secret")}</div>
<div className="flex">
<code
data-testid="oauth-client-submitted-client-secret"
className="bg-subtle text-default w-full truncate rounded-md rounded-r-none px-2 py-1 align-middle font-mono text-sm">
{client.clientSecret}
</code>
<Tooltip side="top" content={t("copy_to_clipboard")}>
<Button
onClick={() => {
copyToClipboard(client.clientSecret ?? "", {
onSuccess: () => showToast(t("client_secret_copied"), "success"),
onFailure: () => showToast(t("error"), "error"),
});
}}
type="button"
size="sm"
className="rounded-l-none"
StartIcon="clipboard">
{t("copy")}
</Button>
</Tooltip>
</div>
<Alert
severity="warning"
message={t("oauth_client_client_secret_one_time_warning")}
className="mt-3"
/>
</div>
) : null}
</div>
<DialogFooter className="mt-6">
<Button type="button" onClick={onClose} data-testid="oauth-client-submitted-done">
{t("done")}
</Button>
</DialogFooter>
</>
</DialogContent>
</Dialog>
);
}
@@ -0,0 +1,366 @@
"use client";
import { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import { Dialog } from "@calcom/features/components/controlled-dialog";
import { useCopy } from "@calcom/lib/hooks/useCopy";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Alert } from "@calcom/ui/components/alert";
import { Badge } from "@calcom/ui/components/badge";
import { Button } from "@calcom/ui/components/button";
import { ConfirmationDialogContent, DialogClose, DialogContent, DialogFooter } from "@calcom/ui/components/dialog";
import { showToast } from "@calcom/ui/components/toast";
import { Tooltip } from "@calcom/ui/components/tooltip";
import { Label, TextArea } from "@calcom/ui/components/form";
import type { OAuthClientCreateFormValues } from "../create/OAuthClientCreateModal";
import { OAuthClientFormFields } from "./OAuthClientFormFields";
type OAuthClientDetails = {
clientId: string;
name: string;
purpose?: string | null;
redirectUri?: string;
websiteUrl?: string | null;
logo?: string | null;
status?: string;
rejectionReason?: string | null;
clientSecret?: string;
isPkceEnabled?: boolean;
clientType?: string;
};
const OAuthClientDetailsDialog = ({
open,
onOpenChange,
client,
onApprove,
onReject,
onUpdate,
onDelete,
isStatusChangePending,
isUpdatePending,
isDeletePending,
}: {
open: boolean;
onOpenChange: (open: boolean) => void;
client: OAuthClientDetails | null;
onApprove?: (clientId: string) => void;
onReject?: (input: { clientId: string; rejectionReason: string }) => void;
onUpdate?: (input: {
clientId: string;
name: string;
purpose: string;
redirectUri: string;
websiteUrl: string;
logo: string;
}) => void;
onDelete?: (clientId: string) => void;
isStatusChangePending?: boolean;
isUpdatePending?: boolean;
isDeletePending?: boolean;
}) => {
const { t } = useLocale();
const { copyToClipboard } = useCopy();
const [logo, setLogo] = useState("");
const [isDeleteConfirmOpen, setIsDeleteConfirmOpen] = useState(false);
const [isRejectConfirmOpen, setIsRejectConfirmOpen] = useState(false);
const [rejectionReason, setRejectionReason] = useState("");
const [showRejectionReasonError, setShowRejectionReasonError] = useState(false);
const form = useForm<OAuthClientCreateFormValues>({
defaultValues: {
name: "",
purpose: "",
redirectUri: "",
websiteUrl: "",
logo: "",
enablePkce: false,
},
});
useEffect(() => {
if (open) return;
setIsDeleteConfirmOpen(false);
setIsRejectConfirmOpen(false);
setRejectionReason("");
setShowRejectionReasonError(false);
}, [open]);
useEffect(() => {
if (!client) return;
const enablePkce =
client.isPkceEnabled ?? (client.clientType ? client.clientType.toUpperCase() === "PUBLIC" : false);
const nextLogo = client.logo ?? "";
setLogo(nextLogo);
form.reset({
name: client.name ?? "",
purpose: client.purpose ?? "",
redirectUri: client.redirectUri ?? "",
websiteUrl: client.websiteUrl ?? "",
logo: nextLogo,
enablePkce,
});
}, [client, form]);
const status = client?.status;
const showAdminActions = Boolean(onApprove) || Boolean(onReject);
const isFormDisabled = showAdminActions;
const canEdit = Boolean(onUpdate) && !isFormDisabled;
const canDelete = Boolean(onDelete) && !showAdminActions;
const handleConfirmReject = () => {
if (!client) return;
const trimmedReason = rejectionReason.trim();
if (trimmedReason.length === 0) {
setShowRejectionReasonError(true);
return;
}
onReject?.({ clientId: client.clientId, rejectionReason: trimmedReason });
setIsRejectConfirmOpen(false);
setRejectionReason("");
setShowRejectionReasonError(false);
};
const clientId = client?.clientId;
const footerActions = (() => {
const closeButton = (
<DialogClose color="minimal" data-testid="oauth-client-details-close">
{t("close")}
</DialogClose>
);
if (showAdminActions) {
const canReject = Boolean(onReject) && (status === "PENDING" || status === "APPROVED");
const canApprove = Boolean(onApprove) && (status === "PENDING" || status === "REJECTED");
return (
<div className="flex gap-2 justify-end items-center w-full">
{closeButton}
{canReject ? (
<Button
type="button"
color="primary"
StartIcon="x"
data-testid="oauth-client-details-reject-trigger"
loading={isStatusChangePending}
onClick={() => {
setIsRejectConfirmOpen(true);
setRejectionReason("");
setShowRejectionReasonError(false);
}}>
{t("reject")}
</Button>
) : null}
{canApprove ? (
<Button
type="button"
color="primary"
StartIcon="check"
data-testid="oauth-client-details-approve-trigger"
loading={isStatusChangePending}
onClick={() => {
if (!clientId) return;
onApprove?.(clientId);
}}>
{t("approve")}
</Button>
) : null}
</div>
);
}
if (canEdit) {
return (
<div className="flex gap-2 justify-end items-center w-full">
{closeButton}
<Button type="submit" loading={isUpdatePending} data-testid="oauth-client-details-save">
{t("save")}
</Button>
</div>
);
}
return <div className="flex justify-end items-center w-full">{closeButton}</div>;
})();
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent enableOverflow type="creation">
{client ? (
<form
data-testid="oauth-client-details-form"
className="space-y-4"
onSubmit={form.handleSubmit((values) => {
if (!canEdit) return;
onUpdate?.({
clientId: client.clientId,
name: values.name.trim() || "",
purpose: values.purpose.trim() || "",
redirectUri: values.redirectUri.trim() || "",
websiteUrl: values.websiteUrl.trim() || "",
logo: values.logo,
});
})}>
{status ? (
<div className="flex justify-start items-center">
<Badge data-testid="oauth-client-details-status-badge" variant={getStatusBadgeVariant(status).variant}>
{t(getStatusBadgeVariant(status).labelKey)}
</Badge>
</div>
) : null}
{status === "PENDING" ? (
<Alert severity="warning" title={t("oauth_client_pending_info_description")} />
) : null}
{status === "APPROVED" ? (
<Alert severity="warning" title={t("oauth_client_approved_reapproval_info")} />
) : null}
{status === "REJECTED" && client.rejectionReason ? (
<div className="text-sm text-subtle" data-testid="oauth-client-details-rejection-reason-display">
<span className="font-medium">{t("oauth_client_rejection_reason")}:</span> {client.rejectionReason}
</div>
) : null}
<div>
<div className="mb-1 text-sm text-subtle">{t("client_id")}</div>
<div className="flex">
<code
data-testid="oauth-client-details-client-id"
className="px-2 py-1 w-full font-mono text-sm truncate align-middle rounded-md rounded-r-none bg-subtle text-default">
{client.clientId}
</code>
<Tooltip side="top" content={t("copy_to_clipboard")}>
<Button
onClick={() => {
copyToClipboard(client.clientId, {
onSuccess: () => showToast(t("client_id_copied"), "success"),
onFailure: () => showToast(t("error"), "error"),
});
}}
type="button"
size="sm"
className="rounded-l-none"
StartIcon="clipboard">
{t("copy")}
</Button>
</Tooltip>
</div>
</div>
<OAuthClientFormFields
form={form}
logo={logo}
setLogo={setLogo}
isClientReadOnly={isFormDisabled}
isPkceLocked
/>
{canDelete ? (
<div className="pt-2">
<Button
type="button"
color="destructive"
StartIcon="trash"
data-testid="oauth-client-details-delete-trigger"
loading={isDeletePending}
className="w-auto"
onClick={() => setIsDeleteConfirmOpen(true)}>
{t("delete_oauth_client")}
</Button>
<Dialog open={isDeleteConfirmOpen} onOpenChange={setIsDeleteConfirmOpen}>
<ConfirmationDialogContent
variety="danger"
title={t("delete_oauth_client")}
cancelBtnText={t("cancel")}
isPending={isDeletePending}
confirmBtn={
<DialogClose
data-testid="oauth-client-details-delete-confirm"
color="primary"
loading={isDeletePending}
onClick={() => {
if (!client) return;
onDelete?.(client.clientId);
}}>
{isDeletePending ? t("deleting") : t("delete")}
</DialogClose>
}>
<p className="mb-4">{t("confirm_delete_oauth_client")}</p>
</ConfirmationDialogContent>
</Dialog>
</div>
) : null}
<DialogFooter className="mt-6">
{footerActions}
</DialogFooter>
<Dialog open={isRejectConfirmOpen} onOpenChange={setIsRejectConfirmOpen}>
<ConfirmationDialogContent
variety="danger"
title={t("reject_oauth_client")}
cancelBtnText={t("cancel")}
confirmBtn={
<Button
type="button"
color="primary"
StartIcon="x"
data-testid="oauth-client-details-reject-confirm"
loading={isStatusChangePending}
className="not-disabled:hover:!bg-error not-disabled:hover:!text-white not-disabled:hover:!border-semantic-error"
onClick={handleConfirmReject}>
{t("reject")}
</Button>
}>
<div className="mt-4 space-y-2">
<Label htmlFor="oauth-rejection-reason">{t("reason_for_rejection")}</Label>
<TextArea
id="oauth-rejection-reason"
data-testid="oauth-client-details-rejection-reason"
value={rejectionReason}
onChange={(e) => {
setRejectionReason(e.target.value);
if (showRejectionReasonError && e.target.value.trim().length > 0) {
setShowRejectionReasonError(false);
}
}}
className={showRejectionReasonError ? "border-error" : undefined}
/>
{showRejectionReasonError ? (
<p className="text-sm text-error">{t("is_required")}</p>
) : null}
</div>
</ConfirmationDialogContent>
</Dialog>
</form>
) : null}
</DialogContent>
</Dialog>
);
};
function getStatusBadgeVariant(status: string) {
switch (status) {
case "APPROVED":
return { variant: "success" as const, labelKey: "approved" as const };
case "REJECTED":
return { variant: "red" as const, labelKey: "rejected" as const };
case "PENDING":
default:
return { variant: "orange" as const, labelKey: "pending" as const };
}
};
export type { OAuthClientDetails };
export { OAuthClientDetailsDialog };
@@ -0,0 +1,163 @@
"use client";
import { useMemo } from "react";
import type { Dispatch, SetStateAction } from "react";
import type { RegisterOptions, UseFormReturn } from "react-hook-form";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Avatar } from "@calcom/ui/components/avatar";
import { Label, Switch, TextArea, TextField } from "@calcom/ui/components/form";
import { Icon } from "@calcom/ui/components/icon";
import { ImageUploader } from "@calcom/ui/components/image-uploader";
import { Tooltip } from "@calcom/ui/components/tooltip";
import type { OAuthClientCreateFormValues } from "../create/OAuthClientCreateModal";
export const OAuthClientFormFields = ({
form,
logo,
setLogo,
isClientReadOnly,
isPkceLocked,
}: {
form: UseFormReturn<OAuthClientCreateFormValues>;
logo: string;
setLogo: Dispatch<SetStateAction<string>>;
isClientReadOnly?: boolean;
isPkceLocked?: boolean;
}) => {
const { t } = useLocale();
const isFormDisabled = Boolean(isClientReadOnly);
const allowUploadingLogo = !isFormDisabled;
const redirectUriValidation: RegisterOptions<OAuthClientCreateFormValues, "redirectUri"> = useMemo(
() => ({
required: true,
validate: (value: string) => {
try {
new URL(value);
return true;
} catch {
return t("invalid_url");
}
},
}),
[t]
);
const websiteUrlValidation: RegisterOptions<OAuthClientCreateFormValues, "websiteUrl"> = useMemo(
() => ({
validate: (value: string) => {
if (!value) return true;
try {
new URL(value);
return true;
} catch {
return t("invalid_url");
}
},
}),
[t]
);
return (
<>
<TextField
{...form.register("name", { required: true })}
label={t("client_name")}
type="text"
id="name"
placeholder={t("client_name_placeholder")}
required
disabled={isFormDisabled}
/>
<div>
<Label htmlFor="purpose" className="text-emphasis mb-2 flex items-center gap-1 text-sm font-medium">
{t("purpose")}
<Tooltip content={t("purpose_tooltip")}>
<span>
<Icon name="info" className="text-subtle h-4 w-4" />
</span>
</Tooltip>
</Label>
<TextArea
{...form.register("purpose", { required: true })}
id="purpose"
placeholder={t("purpose_placeholder")}
required
disabled={isFormDisabled}
/>
</div>
<TextField
{...form.register("redirectUri", redirectUriValidation)}
label={t("redirect_uri")}
type="url"
id="redirectUri"
placeholder={t("redirect_uri_placeholder")}
required
disabled={isFormDisabled}
/>
<TextField
{...form.register("websiteUrl", websiteUrlValidation)}
label={
<span className="flex items-center gap-1">
{t("website_url")}
<Tooltip content={t("website_url_tooltip")}>
<span>
<Icon name="info" className="text-subtle h-4 w-4" />
</span>
</Tooltip>
</span>
}
type="url"
id="websiteUrl"
placeholder={isFormDisabled ? undefined : t("website_url_placeholder")}
disabled={isFormDisabled}
/>
<div>
<Label className="text-emphasis mb-2 block text-sm font-medium">{t("authentication_mode")}</Label>
<div className="flex items-center space-x-3">
<Switch
data-testid="oauth-client-pkce-toggle"
checked={form.watch("enablePkce")}
onCheckedChange={(checked) => form.setValue("enablePkce", checked)}
disabled={isFormDisabled || isPkceLocked}
/>
<span className="text-default text-sm">{t("use_pkce")}</span>
</div>
</div>
<div>
<Label className="text-emphasis mb-2 block text-sm font-medium">{t("logo")}</Label>
<div className="space-y-3">
<div className="flex items-center gap-4">
<Avatar
alt={t("logo")}
fallback={<Icon name="key" className="text-subtle h-6 w-6" />}
imageSrc={logo}
size="lg"
/>
{allowUploadingLogo ? (
<ImageUploader
target="avatar"
id="avatar-upload"
buttonMsg={t("upload_logo")}
testId="oauth-client-logo"
handleAvatarChange={(newLogo: string) => {
setLogo(newLogo);
form.setValue("logo", newLogo);
}}
imageSrc={logo}
disabled={isFormDisabled}
/>
) : null}
</div>
</div>
</div>
</>
);
};