Files
zitadel/apps/login/src/lib/idp.ts
T
30434d176c feat(login): Sign in with Zitadel (#12530)
Closes #11824

# Which Problems Are Solved

The backend supports the dedicated ZITADEL identity provider template
(`AddZitadelProvider`, `IDENTITY_PROVIDER_TYPE_ZITADEL`), but the new
login (login v2)
cannot yet handle providers of this type:

A configured and activated ZITADEL IdP is not rendered as a sign-in
option, because the provider type is missing from the login's component
mapping.

# How the Problems Are Solved

- Regenerated `@zitadel/proto` (`settings/v2/login_settings_pb` in
`types`, `es` and `cjs`)
so `IdentityProviderType.ZITADEL = 13` is available (`idp/v2` was
already up to date).
- `apps/login/src/lib/idp.ts`:
- `idpTypeToSlug` maps `ZITADEL` to the `zitadel` slug, used by the
generic
    `/idp/[provider]/process|failure` routes (no route changes needed).
  - `idpTypeToIdentityProviderType` maps `IDPType.IDP_TYPE_ZITADEL` to
    `IdentityProviderType.ZITADEL`.
- Added `SignInWithZitadel` button
(`apps/login/src/components/idps/sign-in-with-zitadel.tsx`)
with the Zitadel logo as inline SVG: the brand gradient is
theme-independent, accents use
`currentColor` to adapt to light/dark, consistent with the other
provider buttons.
- Registered the Zitadel type in the provider-to-component mapping in
`sign-in-with-idp.tsx`.

No changes to the IdP intent handling are required: user
auto-creation/auto-update consume
the pre-mapped `user_action.create_user` / `update_user` from
`RetrieveIdentityProviderIntent`,
which the backend fills for the Zitadel provider like for any generic
OIDC provider.

# Additional Changes

- Added the `signInWithZitadel` i18n key ("Sign in with Zitadel") to all
15 locale files.
- Extended `idp.test.ts` with the new slug and type mappings and added
the Zitadel type to
  the exhaustive enum-coverage tests (45 tests passing).

# Additional Context

- Part of the "Zitadel as an Identity Provider" epic: #5127
- Enables the customer-portal "support access" flow, where support staff
sign in to a
  customer instance via a pre-configured Zitadel Support IdP

---------

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
2026-08-10 10:27:34 +02:00

81 lines
2.4 KiB
TypeScript

import { IDPType } from "@zitadel/proto/zitadel/idp/v2/idp_pb";
import { IdentityProviderType } from "@zitadel/proto/zitadel/settings/v2/login_settings_pb";
// This maps the IdentityProviderType to a slug which is used in the /success and /failure routes
export function idpTypeToSlug(idpType: IdentityProviderType) {
switch (idpType) {
case IdentityProviderType.GITHUB:
return "github";
case IdentityProviderType.GITHUB_ES:
return "github_es";
case IdentityProviderType.GITLAB:
return "gitlab";
case IdentityProviderType.GITLAB_SELF_HOSTED:
return "gitlab_es";
case IdentityProviderType.APPLE:
return "apple";
case IdentityProviderType.GOOGLE:
return "google";
case IdentityProviderType.AZURE_AD:
return "azure";
case IdentityProviderType.SAML:
return "saml";
case IdentityProviderType.OAUTH:
return "oauth";
case IdentityProviderType.OIDC:
return "oidc";
case IdentityProviderType.LDAP:
return "ldap";
case IdentityProviderType.JWT:
return "jwt";
case IdentityProviderType.ZITADEL:
return "zitadel";
default:
throw new Error("Unknown identity provider type");
}
}
// TODO: this is ugly but needed atm as the getIDPByID returns a IDPType and not a IdentityProviderType
export function idpTypeToIdentityProviderType(idpType: IDPType): IdentityProviderType {
switch (idpType) {
case IDPType.IDP_TYPE_GITHUB:
return IdentityProviderType.GITHUB;
case IDPType.IDP_TYPE_GITHUB_ES:
return IdentityProviderType.GITHUB_ES;
case IDPType.IDP_TYPE_GITLAB:
return IdentityProviderType.GITLAB;
case IDPType.IDP_TYPE_GITLAB_SELF_HOSTED:
return IdentityProviderType.GITLAB_SELF_HOSTED;
case IDPType.IDP_TYPE_APPLE:
return IdentityProviderType.APPLE;
case IDPType.IDP_TYPE_GOOGLE:
return IdentityProviderType.GOOGLE;
case IDPType.IDP_TYPE_AZURE_AD:
return IdentityProviderType.AZURE_AD;
case IDPType.IDP_TYPE_SAML:
return IdentityProviderType.SAML;
case IDPType.IDP_TYPE_OAUTH:
return IdentityProviderType.OAUTH;
case IDPType.IDP_TYPE_OIDC:
return IdentityProviderType.OIDC;
case IDPType.IDP_TYPE_JWT:
return IdentityProviderType.JWT;
case IDPType.IDP_TYPE_ZITADEL:
return IdentityProviderType.ZITADEL;
default:
throw new Error("Unknown identity provider type");
}
}