Newesissrl

payload zitadel plugin

by Newesissrl
Authentication & SSO
v?
Apache-2.0

Overview

Summary generated from the README

Adds a login button and server routes that sign users in through Zitadel using the OIDC authorization code flow with PKCE and the userinfo endpoint. Users are matched by sub or verified email and created if missing. Roles can be read from Zitadel metadata or a claim and mapped to collection roles. Requires mzinga, react, react-i18next and cookie-parser as peer dependencies.

Features

  • Login button for the admin panel with a replaceable component
  • Matches users by sub, or by email only when verified
  • Creates users automatically and maps provider fields to collection fields
  • Reads roles from Zitadel metadata or a configurable claim path
  • Role mapping with a policy for missing roles: keep or reset to default
  • Works with other OIDC providers such as Keycloak

Use cases

  • Enable single sign-on to the admin panel with a Zitadel identity provider
  • Manage editor and admin roles centrally in Zitadel or Keycloak
  • Replace local passwords with OIDC login for content teams

From the author

Extends `payloadcms` with the ability to login through Zitadel

Installation

npm i @newesissrl/payload-zitadel-plugin

11

Stars

1

Forks

4

Open Issues

Yesterday

Last Updated

608

Weekly Downloads

v1.1.1

npm Version

196.5 KB

Unpacked Size

3

Dependencies

GitHub stars

110 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 202611
Dec 5, 202611
Dec 4, 202611
Dec 3, 202611
Dec 2, 202611
Dec 1, 202611
Nov 30, 202611
Nov 29, 202611
Nov 28, 202611
Nov 27, 202611
Nov 26, 202611
Nov 25, 202611
Nov 24, 202611
Nov 23, 202611
Nov 22, 202611
Nov 21, 202611
Nov 20, 202611
Nov 19, 202611
Nov 18, 202611
Nov 17, 202611
Nov 16, 202611
Nov 15, 202611
Nov 14, 202611
Nov 13, 202611
Nov 12, 202611
Nov 11, 202611
Nov 10, 202611
Nov 9, 202611
Nov 8, 202611
Nov 7, 202611
Nov 6, 202611
Nov 5, 202611
Nov 4, 202611
Nov 3, 202611
Nov 2, 202611
Nov 1, 202611
Oct 31, 202611
Oct 30, 202611
Oct 29, 202611
Oct 28, 202611
Oct 27, 202611
Oct 26, 202611
Oct 25, 202611
Oct 24, 202611
Oct 23, 202611
Oct 22, 202611
Oct 21, 202611
Oct 20, 202611
Oct 19, 202611
Oct 18, 202611
Oct 17, 202611
Oct 16, 202611
Oct 15, 202611
Oct 14, 202611
Oct 13, 202611
Oct 12, 202611
Oct 11, 202611
Oct 10, 202611
Oct 9, 202611
Oct 8, 202611
Oct 7, 202611
Oct 6, 202611
Oct 5, 202611
Oct 4, 202611
Oct 3, 202611
Oct 2, 202611
Oct 1, 202611
Sep 30, 202611
Sep 29, 202611
Sep 28, 202611
Sep 27, 202611
Sep 26, 202611
Sep 25, 202611
Sep 24, 202611
Sep 23, 202611
Sep 22, 202611
Sep 21, 202611
Sep 20, 202611
Sep 19, 202611
Sep 18, 202611
Sep 17, 202611
Sep 16, 202611
Sep 15, 202611
Sep 14, 202611
Sep 13, 202611
Sep 12, 202611
Sep 11, 202611
Sep 10, 202611
Sep 9, 202611
Sep 8, 202611
Sep 7, 202611
npm weekly downloads

395+332 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 2026395
Dec 5, 2026142
Dec 4, 2026143
Dec 3, 2026111
Dec 2, 202670
Dec 1, 202669
Nov 30, 202669
Nov 29, 202639
Nov 28, 202640
Nov 27, 202640
Nov 26, 202640
Nov 25, 202642
Nov 24, 202642
Nov 23, 202642
Nov 22, 202611
Nov 21, 202611
Nov 20, 202616
Nov 19, 202618
Nov 18, 202679
Nov 17, 202678
Nov 16, 202678
Nov 15, 202679
Nov 14, 202684
Nov 13, 202681
Nov 12, 202680
Nov 11, 202620
Nov 10, 202654
Nov 9, 202656
Nov 8, 202664
Nov 7, 202659
Nov 6, 202658
Nov 5, 202658
Nov 4, 202659
Nov 3, 202626
Nov 2, 202624
Nov 1, 202613
Oct 31, 202614
Oct 30, 202614
Oct 29, 202612
Oct 28, 20268
Oct 27, 20269
Oct 26, 20269
Oct 25, 202615
Oct 24, 202617
Oct 23, 202615
Oct 22, 202625
Oct 21, 202645
Oct 20, 202643
Oct 19, 202644
Oct 18, 202640
Oct 17, 202638
Oct 16, 202650
Oct 15, 202643
Oct 14, 202665
Oct 13, 202666
Oct 12, 202668
Oct 11, 202668
Oct 10, 202672
Oct 9, 202673
Oct 8, 202687
Oct 7, 202656
Oct 6, 202655
Oct 5, 202652
Oct 4, 202654
Oct 3, 202653
Oct 2, 202646
Oct 1, 202640
Sep 30, 202638
Sep 29, 202654
Sep 28, 202655
Sep 27, 202657
Sep 26, 202657
Sep 25, 202660
Sep 24, 202652
Sep 23, 202646
Sep 22, 202631
Sep 21, 202664
Sep 20, 202666
Sep 19, 202663
Sep 18, 202667
Sep 17, 202667
Sep 16, 202673
Sep 15, 202675
Sep 14, 202644
Sep 13, 202645
Sep 12, 202654
Sep 11, 202656
Sep 10, 202661
Sep 9, 202657
Sep 8, 202657
Sep 7, 202663

Each point is npm's rolling 7-day download count.

Health Score

72/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/733863250-root.svg)](https://payloaddirectory.dev/plugins/733863250-root)
HTML
<a href="https://payloaddirectory.dev/plugins/733863250-root"><img src="https://payloaddirectory.dev/badge/733863250-root.svg" alt="Payload Directory"></a>
Updated Dec 4, 2026Created Dec 20, 2023Published Dec 4, 2026

README

payload-zitadel-plugin

Extends payloadcms with Zitadel integration

Install

yarn add @newesissrl/payload-zitadel-plugin yarn add cookie-parser

mzinga (^1.0.5), react, react-i18next and cookie-parser are peer dependencies: the plugin uses the copies installed by the host application, so only one Mzinga instance is loaded.

Get Started

server.ts

const cookieParser = require("cookie-parser");
import { ZitadelRoutes } from "@newesissrl/payload-zitadel-plugin/dist/routes";
....
app.use(cookieParser());
....
await payload.init(....);
ZitadelRoutes(app);
....

PAYLOAD_PUBLIC env variables

PAYLOAD_PUBLIC_ZITADEL_REDIRECT_URI=http://localhost:3030/zitadel/redirect
PAYLOAD_PUBLIC_ZITADEL_TOKEN_ENDPOINT=http://localhost:8080/oauth/v2/token
PAYLOAD_PUBLIC_ZITADEL_USER_INFO=http://localhost:8080/oidc/v1/userinfo
PAYLOAD_PUBLIC_ZITADEL_AUTHORIZE_ENDPOINT=http://localhost:8080/oauth/v2/authorize
PAYLOAD_PUBLIC_ZITADEL_CLIENT_ID= #the one you get from Zitadel app
PAYLOAD_PUBLIC_ZITADEL_COOKIE_NAME= #(optional) if you want to specify a different cookie name
PAYLOAD_PUBLIC_ZITADEL_COOKIE_SECURE= #(optional) if you want to specify a secure cookie (default = false)
PAYLOAD_PUBLIC_ZITADEL_COOKIE_SAMESITE= #(optional) if you want to specify a different sameSite option for cookie. default = "lax"
PAYLOAD_PUBLIC_COOKIE_DOMAIN= #(optional) if you want to specify a cookie domain
PAYLOAD_PUBLIC_OIDC_SCOPE= #(optional) scopes requested at login, used when the plugin config sets no `scope`. Default: "openid email profile urn:zitadel:iam:user:metadata"

Server-side variables for roles (see "Users and roles"):

OIDC_ROLES_SOURCE= #(optional) "zitadel-metadata" (default) or "claim"
OIDC_ROLES_CLAIM= #(optional) claim path for the "claim" source, e.g. "realm_access.roles"
OIDC_ROLES_MAPPING= #(optional) JSON object mapping provider roles to roles, e.g. {"realm-admin":"admin"}
OIDC_MISSING_ROLES_POLICY= #(optional) "keep" (default) or "default"

Despite the ZITADEL in the variable names, the login flow is standard OIDC (authorization code with PKCE, then the userinfo endpoint), so other providers such as Keycloak work too: point the endpoints at the provider, set PAYLOAD_PUBLIC_OIDC_SCOPE (for example openid email profile), and use the claim roles source.

payload.config.ts

import { ZitadelStrategyPlugin } from "@newesissrl/payload-zitadel-plugin/dist/plugins";
import { LoginButton } from "@newesissrl/payload-zitadel-plugin/dist/components/LoginButton";

const buildConfigAsync = async () => {
    const zitadelPlugin = await ZitadelStrategyPlugin({
      ui: {
        beforeOrAfterLogin? // where to place the button (before|after, default = "after")
        loginButtonLabel? // the label to use for the login button (default = "login-with-zitadel")
        LoginButton: LoginButton // the component to use for the login button
      },
      auth: {
        authorizeEndpoint: process.env.PAYLOAD_PUBLIC_ZITADEL_AUTHORIZE_ENDPOINT,
        clientID: process.env.PAYLOAD_PUBLIC_ZITADEL_CLIENT_ID,
        redirectUri: process.env.PAYLOAD_PUBLIC_ZITADEL_REDIRECT_URI,
      },
      fieldsMappings: [], // useful to remap fields from idP to the desired `required` fields
      /*
      [{
        from: "name",
        to: "first_name"
      },
      ...]
      */
     loggerOptions? // optional logging options for `pino` library
     missingRolesPolicy? // "keep" (default) or "default": see "Users and roles" below
     roles? // { source, claim, mapping }: overrides the OIDC_ROLES_* variables, see "Users and roles"
    });
    return buildConfig({
      .....
      plugins: [...., zitadelPlugin],
    })
}

Users and roles

Finding and creating users

On each request that carries the Zitadel cookie, the plugin reads the user from the PAYLOAD_PUBLIC_ZITADEL_USER_INFO endpoint and looks for a matching user in the auth collection:

  1. By sub (the Zitadel user ID). The plugin adds a sub field to the auth collection. The field is indexed and can't be created or changed through the API; only the plugin writes it.
  2. By email, only if the userinfo response has email_verified: true. Unverified emails are never used to link an existing account.

If no user matches, the plugin creates one. If more than one user has the same sub, or the userinfo response has no sub, the login is refused.

sub isn't a unique index, because existing documents may store sub as null or an empty string, which a unique index would reject. To enforce uniqueness at the database level, clean those values up first, then add a unique sparse index on sub.

Where roles come from

OIDC_ROLES_SOURCE (or the roles.source plugin option) chooses the source:

SourceReadsUse for
zitadel-metadata (default)The Zitadel user metadata key rolesCompatibility with earlier versions
claimThe claim at OIDC_ROLES_CLAIM in the userinfo responseZitadel project roles, Keycloak, any OIDC provider

Claim examples:

ProviderOIDC_ROLES_CLAIMProvider setting
Zitadel project rolesurn:zitadel:iam:org:project:rolesOn the project, enable "Assert Roles on Authentication" so roles are in the userinfo response.
Keycloak realm rolesrealm_access.rolesOn the "realm roles" mapper of the roles client scope, enable "Add to userinfo".
Keycloak client rolesresource_access.<client-id>.rolesSame, on the "client roles" mapper.
Providers with groupsgroupsAdd a groups claim to the userinfo response.

A claim value can be an array of strings, a comma-separated string, a JSON array in a string, or an object whose keys are the roles (Zitadel's project roles format). The path is first tried as a whole key, then split on dots.

OIDC_ROLES_MAPPING translates provider roles to roles of the auth collection, for example {"realm-admin":"admin","content-team":["editor"]}. Roles without a mapping pass through unchanged. Whatever the source, roles that aren't options of the roles field are then dropped with a warning, and missingRolesPolicy applies when none is left.

Roles from Zitadel metadata

Request the urn:zitadel:iam:user:metadata scope (it's in the default scope) and set a user metadata key named roles in Zitadel. Its value can be:

  • a comma-separated list: admin,editor (spaces and quotes around values are ignored);
  • a JSON array: ["admin","editor"].

The plugin trims values, drops empty ones and duplicates, and writes the result to the user's roles field. Roles that aren't options of the auth collection's roles field are dropped with a warning; they don't make the login fail.

missingRolesPolicy decides what happens when the metadata has no roles key, or none of its roles is known:

  • "keep" (default): the user's roles are left unchanged. New users get the field's default value.
  • "default": the user's roles are reset to the roles field's defaultValue. Use this when Zitadel is the only place roles are managed, so that removing the metadata key also removes the roles.

Notes

If you want to override the LoginButton component, your React component must accept those properties:

loginButtonLabel,
codeChallenge,
authorizeEndpoint,
redirectUri,
clientID,
scope,
codeChallengeMethod,
state

Similar plugins