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.
Extends `payloadcms` with the ability to login through Zitadel
Installation
npm i @newesissrl/payload-zitadel-plugin11
Stars
1
Forks
4
Open Issues
Yesterday
Last Updated
608
Weekly Downloads
v1.1.1
npm Version
196.5 KB
Unpacked Size
3
Dependencies
110 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 11 |
| Dec 5, 2026 | 11 |
| Dec 4, 2026 | 11 |
| Dec 3, 2026 | 11 |
| Dec 2, 2026 | 11 |
| Dec 1, 2026 | 11 |
| Nov 30, 2026 | 11 |
| Nov 29, 2026 | 11 |
| Nov 28, 2026 | 11 |
| Nov 27, 2026 | 11 |
| Nov 26, 2026 | 11 |
| Nov 25, 2026 | 11 |
| Nov 24, 2026 | 11 |
| Nov 23, 2026 | 11 |
| Nov 22, 2026 | 11 |
| Nov 21, 2026 | 11 |
| Nov 20, 2026 | 11 |
| Nov 19, 2026 | 11 |
| Nov 18, 2026 | 11 |
| Nov 17, 2026 | 11 |
| Nov 16, 2026 | 11 |
| Nov 15, 2026 | 11 |
| Nov 14, 2026 | 11 |
| Nov 13, 2026 | 11 |
| Nov 12, 2026 | 11 |
| Nov 11, 2026 | 11 |
| Nov 10, 2026 | 11 |
| Nov 9, 2026 | 11 |
| Nov 8, 2026 | 11 |
| Nov 7, 2026 | 11 |
| Nov 6, 2026 | 11 |
| Nov 5, 2026 | 11 |
| Nov 4, 2026 | 11 |
| Nov 3, 2026 | 11 |
| Nov 2, 2026 | 11 |
| Nov 1, 2026 | 11 |
| Oct 31, 2026 | 11 |
| Oct 30, 2026 | 11 |
| Oct 29, 2026 | 11 |
| Oct 28, 2026 | 11 |
| Oct 27, 2026 | 11 |
| Oct 26, 2026 | 11 |
| Oct 25, 2026 | 11 |
| Oct 24, 2026 | 11 |
| Oct 23, 2026 | 11 |
| Oct 22, 2026 | 11 |
| Oct 21, 2026 | 11 |
| Oct 20, 2026 | 11 |
| Oct 19, 2026 | 11 |
| Oct 18, 2026 | 11 |
| Oct 17, 2026 | 11 |
| Oct 16, 2026 | 11 |
| Oct 15, 2026 | 11 |
| Oct 14, 2026 | 11 |
| Oct 13, 2026 | 11 |
| Oct 12, 2026 | 11 |
| Oct 11, 2026 | 11 |
| Oct 10, 2026 | 11 |
| Oct 9, 2026 | 11 |
| Oct 8, 2026 | 11 |
| Oct 7, 2026 | 11 |
| Oct 6, 2026 | 11 |
| Oct 5, 2026 | 11 |
| Oct 4, 2026 | 11 |
| Oct 3, 2026 | 11 |
| Oct 2, 2026 | 11 |
| Oct 1, 2026 | 11 |
| Sep 30, 2026 | 11 |
| Sep 29, 2026 | 11 |
| Sep 28, 2026 | 11 |
| Sep 27, 2026 | 11 |
| Sep 26, 2026 | 11 |
| Sep 25, 2026 | 11 |
| Sep 24, 2026 | 11 |
| Sep 23, 2026 | 11 |
| Sep 22, 2026 | 11 |
| Sep 21, 2026 | 11 |
| Sep 20, 2026 | 11 |
| Sep 19, 2026 | 11 |
| Sep 18, 2026 | 11 |
| Sep 17, 2026 | 11 |
| Sep 16, 2026 | 11 |
| Sep 15, 2026 | 11 |
| Sep 14, 2026 | 11 |
| Sep 13, 2026 | 11 |
| Sep 12, 2026 | 11 |
| Sep 11, 2026 | 11 |
| Sep 10, 2026 | 11 |
| Sep 9, 2026 | 11 |
| Sep 8, 2026 | 11 |
| Sep 7, 2026 | 11 |
395+332 since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 395 |
| Dec 5, 2026 | 142 |
| Dec 4, 2026 | 143 |
| Dec 3, 2026 | 111 |
| Dec 2, 2026 | 70 |
| Dec 1, 2026 | 69 |
| Nov 30, 2026 | 69 |
| Nov 29, 2026 | 39 |
| Nov 28, 2026 | 40 |
| Nov 27, 2026 | 40 |
| Nov 26, 2026 | 40 |
| Nov 25, 2026 | 42 |
| Nov 24, 2026 | 42 |
| Nov 23, 2026 | 42 |
| Nov 22, 2026 | 11 |
| Nov 21, 2026 | 11 |
| Nov 20, 2026 | 16 |
| Nov 19, 2026 | 18 |
| Nov 18, 2026 | 79 |
| Nov 17, 2026 | 78 |
| Nov 16, 2026 | 78 |
| Nov 15, 2026 | 79 |
| Nov 14, 2026 | 84 |
| Nov 13, 2026 | 81 |
| Nov 12, 2026 | 80 |
| Nov 11, 2026 | 20 |
| Nov 10, 2026 | 54 |
| Nov 9, 2026 | 56 |
| Nov 8, 2026 | 64 |
| Nov 7, 2026 | 59 |
| Nov 6, 2026 | 58 |
| Nov 5, 2026 | 58 |
| Nov 4, 2026 | 59 |
| Nov 3, 2026 | 26 |
| Nov 2, 2026 | 24 |
| Nov 1, 2026 | 13 |
| Oct 31, 2026 | 14 |
| Oct 30, 2026 | 14 |
| Oct 29, 2026 | 12 |
| Oct 28, 2026 | 8 |
| Oct 27, 2026 | 9 |
| Oct 26, 2026 | 9 |
| Oct 25, 2026 | 15 |
| Oct 24, 2026 | 17 |
| Oct 23, 2026 | 15 |
| Oct 22, 2026 | 25 |
| Oct 21, 2026 | 45 |
| Oct 20, 2026 | 43 |
| Oct 19, 2026 | 44 |
| Oct 18, 2026 | 40 |
| Oct 17, 2026 | 38 |
| Oct 16, 2026 | 50 |
| Oct 15, 2026 | 43 |
| Oct 14, 2026 | 65 |
| Oct 13, 2026 | 66 |
| Oct 12, 2026 | 68 |
| Oct 11, 2026 | 68 |
| Oct 10, 2026 | 72 |
| Oct 9, 2026 | 73 |
| Oct 8, 2026 | 87 |
| Oct 7, 2026 | 56 |
| Oct 6, 2026 | 55 |
| Oct 5, 2026 | 52 |
| Oct 4, 2026 | 54 |
| Oct 3, 2026 | 53 |
| Oct 2, 2026 | 46 |
| Oct 1, 2026 | 40 |
| Sep 30, 2026 | 38 |
| Sep 29, 2026 | 54 |
| Sep 28, 2026 | 55 |
| Sep 27, 2026 | 57 |
| Sep 26, 2026 | 57 |
| Sep 25, 2026 | 60 |
| Sep 24, 2026 | 52 |
| Sep 23, 2026 | 46 |
| Sep 22, 2026 | 31 |
| Sep 21, 2026 | 64 |
| Sep 20, 2026 | 66 |
| Sep 19, 2026 | 63 |
| Sep 18, 2026 | 67 |
| Sep 17, 2026 | 67 |
| Sep 16, 2026 | 73 |
| Sep 15, 2026 | 75 |
| Sep 14, 2026 | 44 |
| Sep 13, 2026 | 45 |
| Sep 12, 2026 | 54 |
| Sep 11, 2026 | 56 |
| Sep 10, 2026 | 61 |
| Sep 9, 2026 | 57 |
| Sep 8, 2026 | 57 |
| Sep 7, 2026 | 63 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/733863250-root)<a href="https://payloaddirectory.dev/plugins/733863250-root"><img src="https://payloaddirectory.dev/badge/733863250-root.svg" alt="Payload Directory"></a>README
Extends payloadcms with Zitadel integration
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.
const cookieParser = require("cookie-parser");
import { ZitadelRoutes } from "@newesissrl/payload-zitadel-plugin/dist/routes";
....
app.use(cookieParser());
....
await payload.init(....);
ZitadelRoutes(app);
....
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.
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],
})
}
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:
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.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.
OIDC_ROLES_SOURCE (or the roles.source plugin option) chooses the source:
| Source | Reads | Use for |
|---|---|---|
zitadel-metadata (default) | The Zitadel user metadata key roles | Compatibility with earlier versions |
claim | The claim at OIDC_ROLES_CLAIM in the userinfo response | Zitadel project roles, Keycloak, any OIDC provider |
Claim examples:
| Provider | OIDC_ROLES_CLAIM | Provider setting |
|---|---|---|
| Zitadel project roles | urn:zitadel:iam:org:project:roles | On the project, enable "Assert Roles on Authentication" so roles are in the userinfo response. |
| Keycloak realm roles | realm_access.roles | On the "realm roles" mapper of the roles client scope, enable "Add to userinfo". |
| Keycloak client roles | resource_access.<client-id>.roles | Same, on the "client roles" mapper. |
| Providers with groups | groups | Add 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.
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:
admin,editor (spaces and quotes around values are ignored);["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.If you want to override the LoginButton component, your React component must accept those properties:
loginButtonLabel,
codeChallenge,
authorizeEndpoint,
redirectUri,
clientID,
scope,
codeChallengeMethod,
state
Topics
oidc
OpenID Connect single sign-on for Payload using Authorization Code Flow with PKCE and native Payload sessions
65745/wk0v3
payload keycloak
Keycloak SSO-only authentication for Payload 3 using OIDC with PKCE and permission-based access helpers
5511/wk0v3
payload auth
Replace Payload's built-in auth with Better Auth for a shared admin and frontend session
7021.0k/wk349v3
payload github auth
Sign in to the Payload admin with a GitHub App, with access rules by email, org or team
6021/wk0v4
payload auth plugin
Authentication plugin adding OAuth, OIDC, SSO and passkey sign-in to Payload CMS
594.7k/wk310v3
payload authjs
Sign in to Payload CMS through Auth.js 5 providers and use the Auth.js session as the Payload user
903.1k/wk206v3