Files
zitadel/packages/zitadel-next/src/components/SignInWithIDP.tsx

104 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-07-18 13:58:33 +02:00
import { ReactNode } from "react";
import {
ZitadelServer,
settings,
GetActiveIdentityProvidersResponse,
IdentityProvider,
IdentityProviderType,
} from "@zitadel/server";
import {
SignInWithGitlab,
SignInWithAzureAD,
SignInWithGoogle,
SignInWithGithub,
} from "@zitadel/react";
export interface SignInWithIDPProps {
children?: ReactNode;
server: ZitadelServer;
orgId?: string;
}
function getIdentityProviders(
server: ZitadelServer,
orgId?: string
): Promise<IdentityProvider[] | undefined> {
const settingsService = settings.getSettings(server);
console.log("req");
return settingsService
.getActiveIdentityProviders(
orgId ? { ctx: { orgId } } : { ctx: { instance: true } },
{}
)
.then((resp: GetActiveIdentityProvidersResponse) => {
return resp.identityProviders;
});
}
export async function SignInWithIDP(props: SignInWithIDPProps) {
const identityProviders = await getIdentityProviders(
props.server,
props.orgId
);
console.log(identityProviders);
return (
<div className="ztdl-next-flex ztdl-next-flex-col ztdl-next-w-full ztdl-next-space-y-2 ztdl-next-text-sm">
{identityProviders &&
identityProviders.map((idp, i) => {
switch (idp.type) {
case IdentityProviderType.IDENTITY_PROVIDER_TYPE_GITHUB:
2023-07-26 09:30:39 +02:00
return (
<SignInWithGithub
key={`idp-${i}`}
name={idp.name}
></SignInWithGithub>
);
2023-07-18 13:58:33 +02:00
case IdentityProviderType.IDENTITY_PROVIDER_TYPE_GITHUB_ES:
2023-07-26 09:30:39 +02:00
return (
<SignInWithGithub
key={`idp-${i}`}
name={idp.name}
></SignInWithGithub>
);
2023-07-18 13:58:33 +02:00
case IdentityProviderType.IDENTITY_PROVIDER_TYPE_AZURE_AD:
2023-07-26 09:30:39 +02:00
return (
<SignInWithAzureAD
key={`idp-${i}`}
name={idp.name}
></SignInWithAzureAD>
);
2023-07-18 13:58:33 +02:00
case IdentityProviderType.IDENTITY_PROVIDER_TYPE_GOOGLE:
2023-07-26 09:30:39 +02:00
return (
<SignInWithGoogle
key={`idp-${i}`}
name={idp.name}
></SignInWithGoogle>
);
2023-07-18 13:58:33 +02:00
case IdentityProviderType.IDENTITY_PROVIDER_TYPE_GITLAB:
2023-07-26 09:30:39 +02:00
return (
<SignInWithGitlab
key={`idp-${i}`}
name={idp.name}
></SignInWithGitlab>
);
2023-07-18 13:58:33 +02:00
case IdentityProviderType.IDENTITY_PROVIDER_TYPE_GITLAB_SELF_HOSTED:
2023-07-26 09:30:39 +02:00
return (
<SignInWithGitlab
key={`idp-${i}`}
name={idp.name}
></SignInWithGitlab>
);
2023-07-18 13:58:33 +02:00
default:
2023-07-26 09:30:39 +02:00
return <div>{idp.name}</div>;
2023-07-18 13:58:33 +02:00
}
})}
{props.children}
</div>
);
}
SignInWithIDP.displayName = "SignInWithIDP";