Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPF-644 Remove auth0 specific code #1552

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Domain\Integrations\Controllers;

use App\Auth0\Repositories\Auth0ClientRepository;
use App\Domain\Auth\CurrentUser;
use App\Domain\Contacts\ContactType;
use App\Domain\Contacts\Repositories\ContactKeyVisibilityRepository;
Expand Down Expand Up @@ -73,7 +72,6 @@ public function __construct(
private readonly OrganizationRepository $organizationRepository,
private readonly UdbOrganizerRepository $organizerRepository,
private readonly CouponRepository $couponRepository,
private readonly Auth0ClientRepository $auth0ClientRepository,
private readonly UiTiDv1ConsumerRepository $uitidV1ConsumerRepository,
private readonly KeycloakClientRepository $keycloakClientRepository,
private readonly KeyVisibilityUpgradeRepository $keyVisibilityUpgradeRepository,
Expand All @@ -93,16 +91,14 @@ public function index(Request $request): Response

$integrationIds = array_map(fn ($integration) => $integration->id, $integrationsData->collection->toArray());

$auth0Clients = $this->auth0ClientRepository->getByIntegrationIds($integrationIds);
$uitidV1Consumers = $this->uitidV1ConsumerRepository->getByIntegrationIds($integrationIds);
$keycloakClients = $this->keycloakClientRepository->getByIntegrationIds($integrationIds);

return Inertia::render('Integrations/Index', [
'integrations' => $integrationsData->collection->map(fn (Integration $integration) => $integration->toArray()),
'credentials' => [
'auth0' => $auth0Clients,
'uitidV1' => $uitidV1Consumers,
'keycloak' => $keycloakClients,
'legacyConsumers' => $uitidV1Consumers,
'clients' => $keycloakClients,
],
'paginationInfo' => $integrationsData->paginationInfo,
]);
Expand Down
2 changes: 1 addition & 1 deletion app/Domain/Integrations/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function toArray(): array
'urls' => $this->urls,
'organization' => $this->organization,
'organizers' => $this->udbOrganizers,
'authClients' => $this->auth0Clients,
'authClients' => $this->keycloakClients,
LucWollants marked this conversation as resolved.
Show resolved Hide resolved
'legacyAuthConsumers' => $this->uiTiDv1Consumers,
'keycloakClients' => $this->keycloakClients,
'subscription' => $this->subscription,
Expand Down
16 changes: 5 additions & 11 deletions resources/ts/Components/IntegrationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ import { usePolling } from "../hooks/usePolling";
import { ButtonSecondary } from "./ButtonSecondary";
import { IntegrationClientCredentials } from "./IntegrationClientCredential";

type Props = Integration &
Credentials & {
onEdit: (id: string) => void;
};

const productTypeToPath = {
uitpas: "/uitpas/getting-started",
"entry-api": "/uitdatabank/entry-api/introduction",
Expand Down Expand Up @@ -59,6 +54,11 @@ export const OpenWidgetBuilderButton = ({
);
};

type Props = Integration &
Credentials & {
onEdit: (id: string) => void;
};

export const IntegrationCard = ({
id,
name,
Expand All @@ -68,8 +68,6 @@ export const IntegrationCard = ({
legacyProdConsumer,
testClient,
prodClient,
keycloakTestClient,
keycloakProdClient,
keyVisibility,
onEdit,
}: Props) => {
Expand All @@ -82,8 +80,6 @@ export const IntegrationCard = ({
legacyProdConsumer,
testClient,
prodClient,
keycloakTestClient,
keycloakProdClient,
].some(Boolean);

usePolling(!hasAnyCredentials, { only: ["credentials"] });
Expand All @@ -105,7 +101,6 @@ export const IntegrationCard = ({
<div className="flex flex-col gap-2">
<IntegrationClientCredentials
client={testClient}
keycloakClient={keycloakTestClient}
status={status}
type={type}
isLive={false}
Expand Down Expand Up @@ -163,7 +158,6 @@ export const IntegrationCard = ({
{status === IntegrationStatus.Active && (
<IntegrationClientCredentials
client={prodClient}
keycloakClient={keycloakProdClient}
status={status}
type={type}
isLive={true}
Expand Down
12 changes: 3 additions & 9 deletions resources/ts/Components/IntegrationClientCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { IntegrationType } from "../types/IntegrationType";
import { IntegrationStatus } from "../types/IntegrationStatus";
import { Alert } from "./Alert";
import type { Integration } from "../types/Integration";
import type { AuthClient, KeycloakClient } from "../types/Credentials";
import { usePageProps } from "../hooks/usePageProps";
import type { AuthClient } from "../types/Credentials";

type Props = {
client: {
Expand Down Expand Up @@ -36,28 +35,23 @@ export const IntegrationClientCredential = ({ client }: Props) => {

export const IntegrationClientCredentials = ({
client,
keycloakClient,
status,
type,
isLive,
}: Pick<Integration, "status" | "type"> & {
client: AuthClient | undefined;
keycloakClient?: KeycloakClient;
isLive: boolean;
}) => {
const { t } = useTranslation();
const { config } = usePageProps();

const clientToShow =
config.keycloak.creationEnabled && keycloakClient ? keycloakClient : client;
const clientWithLabels = [
{
label: "details.credentials.client_id",
value: clientToShow?.clientId,
value: client?.clientId,
},
{
label: "details.credentials.client_secret",
value: clientToShow?.clientSecret,
value: client?.clientSecret,
},
];

Expand Down
37 changes: 3 additions & 34 deletions resources/ts/Components/Integrations/Detail/Credentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { IntegrationType } from "../../../types/IntegrationType";
import { CredentialsWidgets } from "./CredentialsWidgets";
import type {
AuthClient,
KeycloakClient,
LegacyAuthConsumer,
} from "../../../types/Credentials";
import type { Integration } from "../../../types/Integration";
Expand All @@ -14,9 +13,7 @@ import { useTranslation } from "react-i18next";
import { usePolling } from "../../../hooks/usePolling";
import { KeyVisibility } from "../../../types/KeyVisibility";
import { UiTiDv1Environment } from "../../../types/UiTiDv1Environment";
import { Auth0Tenant } from "../../../types/Auth0Tenant";
import { KeycloakEnvironment } from "../../../types/KeycloakEnvironment";
import { usePageProps } from "../../../hooks/usePageProps";

type Props = Integration & {
email: string;
Expand All @@ -28,8 +25,6 @@ export type Credentials = {
prodClient?: AuthClient;
legacyTestConsumer?: LegacyAuthConsumer;
legacyProdConsumer?: LegacyAuthConsumer;
keycloakTestClient?: KeycloakClient;
keycloakProdClient?: KeycloakClient;
};

export const Credentials = ({
Expand All @@ -42,30 +37,10 @@ export const Credentials = ({
keyVisibilityUpgrade,
legacyAuthConsumers,
authClients,
keycloakClients,
oldCredentialsExpirationDate,
}: Props) => {
const { t } = useTranslation();
const { config } = usePageProps();
const hasCredentials = useMemo(() => {
if (keyVisibility === KeyVisibility.v1 && !keyVisibilityUpgrade) {
return legacyAuthConsumers.length > 0;
}

const credentials: unknown[][] = [legacyAuthConsumers];

if (config.keycloak.enabled) {
credentials.push(keycloakClients);
}

return credentials.every((it) => it.length > 0);
}, [
config.keycloak.enabled,
keyVisibility,
keyVisibilityUpgrade,
keycloakClients,
legacyAuthConsumers,
]);
const hasCredentials = legacyAuthConsumers.length > 0;

const isV1Upgraded =
keyVisibility === KeyVisibility.v1 && !!keyVisibilityUpgrade;
Expand All @@ -79,19 +54,13 @@ export const Credentials = ({
(consumer) => consumer.environment === UiTiDv1Environment.Production
),
testClient: authClients.find(
(client) => client.tenant === Auth0Tenant.Testing
),
prodClient: authClients.find(
(client) => client.tenant === Auth0Tenant.Production
),
keycloakTestClient: keycloakClients.find(
(client) => client.environment === KeycloakEnvironment.Testing
),
keycloakProdClient: keycloakClients.find(
prodClient: authClients.find(
(client) => client.environment === KeycloakEnvironment.Production
),
}),
[legacyAuthConsumers, authClients, keycloakClients]
[legacyAuthConsumers, authClients]
);

if (!hasCredentials) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type Props = Pick<
export const CredentialsAuthClients = ({
testClient,
prodClient,
keycloakTestClient,
keycloakProdClient,
id,
status,
email,
Expand Down Expand Up @@ -84,7 +82,6 @@ export const CredentialsAuthClients = ({
</Heading>
<IntegrationClientCredentials
client={testClient}
keycloakClient={keycloakTestClient}
status={status}
type={type}
isLive={false}
Expand All @@ -99,7 +96,6 @@ export const CredentialsAuthClients = ({
<div className="flex flex-col gap-3">
<IntegrationClientCredentials
client={prodClient}
keycloakClient={keycloakProdClient}
status={status}
type={type}
isLive={true}
Expand Down
27 changes: 8 additions & 19 deletions resources/ts/Pages/Integrations/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import type { PaginationInfo } from "../../types/PaginationInfo";
import { Page } from "../../Components/Page";
import { QuestionDialog } from "../../Components/QuestionDialog";
import { IconLink } from "../../Components/IconLink";
import { Auth0Tenant } from "../../types/Auth0Tenant";
import { UiTiDv1Environment } from "../../types/UiTiDv1Environment";
import type { Credentials } from "../../types/Credentials";
import type { Integration } from "../../types/Integration";
import { router } from "@inertiajs/react";
import { KeycloakEnvironment } from "../../types/KeycloakEnvironment";
import { WelcomeSection } from "../../Components/WelcomeSection";
import { KeycloakEnvironment } from "../../types/KeycloakEnvironment";

type Props = {
integrations: Integration[];
Expand Down Expand Up @@ -52,39 +51,29 @@ const Index = ({ integrations, paginationInfo, credentials }: Props) => {
integrations.map((integration) => ({
...integration,
credentials: {
testClient: credentials.auth0.find(
testClient: credentials.clients.find(
(client) =>
client.integrationId === integration.id &&
client.tenant === Auth0Tenant.Testing
client.environment === KeycloakEnvironment.Testing
),
prodClient: credentials.auth0.find(
prodClient: credentials.clients.find(
(client) =>
client.integrationId === integration.id &&
client.tenant === Auth0Tenant.Production
client.environment === KeycloakEnvironment.Production
),
legacyTestConsumer: credentials.uitidV1.find(
legacyTestConsumer: credentials.legacyConsumers.find(
(client) =>
client.integrationId === integration.id &&
client.environment === UiTiDv1Environment.Testing
),
legacyProdConsumer: credentials.uitidV1.find(
legacyProdConsumer: credentials.legacyConsumers.find(
(client) =>
client.integrationId === integration.id &&
client.environment === UiTiDv1Environment.Production
),
keycloakTestClient: credentials.keycloak.find(
(client) =>
client.integrationId === integration.id &&
client.environment === KeycloakEnvironment.Testing
),
keycloakProdClient: credentials.keycloak.find(
(client) =>
client.integrationId === integration.id &&
client.environment === KeycloakEnvironment.Production
),
},
})),
[integrations, credentials.auth0, credentials.uitidV1, credentials.keycloak]
[integrations, credentials.legacyConsumers, credentials.clients]
);

const handleDeleteIntegration = () => {
Expand Down
3 changes: 1 addition & 2 deletions resources/ts/Pages/Integrations/New.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { FormEvent } from "react";
import { useEffect } from "react";
import { type FormEvent, useEffect } from "react";
import React, { useState } from "react";
import { useForm } from "@inertiajs/react";
import { Heading } from "../../Components/Heading";
Expand Down
9 changes: 0 additions & 9 deletions resources/ts/types/Auth0Tenant.ts

This file was deleted.

14 changes: 3 additions & 11 deletions resources/ts/types/Credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Auth0Tenant } from "./Auth0Tenant";
import type { KeycloakEnvironment } from "./KeycloakEnvironment";
import type { UiTiDv1Environment } from "./UiTiDv1Environment";

Expand All @@ -12,21 +11,14 @@ export type LegacyAuthConsumer = {
integrationId: string;
};
export type AuthClient = {
clientId: string;
clientSecret: string;
id: string;
integrationId: string;
tenant: Auth0Tenant;
};
export type KeycloakClient = {
clientId: string;
clientSecret: string;
environment: KeycloakEnvironment;
id: string;
integrationId: string;
};

export type Credentials = {
auth0: AuthClient[];
uitidV1: LegacyAuthConsumer[];
keycloak: KeycloakClient[];
legacyConsumers: LegacyAuthConsumer[];
clients: AuthClient[];
};
7 changes: 1 addition & 6 deletions resources/ts/types/Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import type { Contact } from "./Contact";
import type { Organization } from "./Organization";
import type { Subscription } from "./Subscription";
import type { IntegrationUrl } from "./IntegrationUrl";
import type {
AuthClient,
KeycloakClient,
LegacyAuthConsumer,
} from "./Credentials";
import type { AuthClient, LegacyAuthConsumer } from "./Credentials";
import type { KeyVisibility } from "./KeyVisibility";

export type Coupon = {
Expand Down Expand Up @@ -41,7 +37,6 @@ export type Integration = {
urls: IntegrationUrl[];
authClients: AuthClient[];
legacyAuthConsumers: LegacyAuthConsumer[];
keycloakClients: KeycloakClient[];
keyVisibility: KeyVisibility;
keyVisibilityUpgrade: KeyVisibilityUpgrade | null;
};
4 changes: 0 additions & 4 deletions resources/ts/types/PageProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ type Config = {
enabled: boolean;
dsn: string;
};
keycloak: {
enabled: boolean;
creationEnabled: boolean;
};
};

export type PageProps = {
Expand Down
Loading