Replaces local Payload users and passwords with Keycloak sign-in. It registers an auth strategy that verifies Keycloak access tokens via JWKS, creates users on first login, and adds admin login and logout through Authorization Code with PKCE. Permissions are read from a userinfo claim and exposed through access helpers. Requires a public Keycloak client with Revoke Refresh Token turned off, and Payload 3.
Keycloak SSO authentication for Payload CMS 3: OIDC auth strategy, admin login/logout, silent refresh and permission-based access control
Installation
npm i payload-keycloak0
Stars
0
Forks
9
Open Issues
3 days ago
Last Updated
12
Weekly Downloads
v1.0.1
npm Version
117.5 KB
Unpacked Size
1
Dependencies
00 since Sep 13
| Date | Stars |
|---|---|
| Dec 5, 2026 | 0 |
| Dec 4, 2026 | 0 |
| Dec 3, 2026 | 0 |
| Dec 2, 2026 | 0 |
| Dec 1, 2026 | 0 |
| Nov 30, 2026 | 0 |
| Nov 29, 2026 | 0 |
| Nov 28, 2026 | 0 |
| Nov 27, 2026 | 0 |
| Nov 26, 2026 | 0 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
| Nov 22, 2026 | 0 |
| Nov 21, 2026 | 0 |
| Nov 20, 2026 | 0 |
| Nov 19, 2026 | 0 |
| Nov 18, 2026 | 0 |
| Nov 17, 2026 | 0 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 0 |
| Nov 13, 2026 | 0 |
| Nov 12, 2026 | 0 |
| Nov 11, 2026 | 0 |
| Nov 10, 2026 | 0 |
| Nov 9, 2026 | 0 |
| Nov 8, 2026 | 0 |
| Nov 7, 2026 | 0 |
| Nov 6, 2026 | 0 |
| Nov 5, 2026 | 0 |
| Nov 4, 2026 | 0 |
| Nov 3, 2026 | 0 |
| Nov 2, 2026 | 0 |
| Nov 1, 2026 | 0 |
| Oct 31, 2026 | 0 |
| Oct 30, 2026 | 0 |
| Oct 29, 2026 | 0 |
| Oct 28, 2026 | 0 |
| Oct 27, 2026 | 0 |
| Oct 26, 2026 | 0 |
| Oct 25, 2026 | 0 |
| Oct 24, 2026 | 0 |
| Oct 23, 2026 | 0 |
| Oct 22, 2026 | 0 |
| Oct 21, 2026 | 0 |
| Oct 20, 2026 | 0 |
| Oct 19, 2026 | 0 |
| Oct 18, 2026 | 0 |
| Oct 17, 2026 | 0 |
| Oct 16, 2026 | 0 |
| Oct 15, 2026 | 0 |
| Oct 14, 2026 | 0 |
| Oct 13, 2026 | 0 |
| Oct 12, 2026 | 0 |
| Oct 11, 2026 | 0 |
| Oct 10, 2026 | 0 |
| Oct 9, 2026 | 0 |
| Oct 8, 2026 | 0 |
| Oct 7, 2026 | 0 |
| Oct 6, 2026 | 0 |
| Oct 5, 2026 | 0 |
| Oct 4, 2026 | 0 |
| Oct 3, 2026 | 0 |
| Oct 2, 2026 | 0 |
| Oct 1, 2026 | 0 |
| Sep 30, 2026 | 0 |
| Sep 29, 2026 | 0 |
| Sep 28, 2026 | 0 |
| Sep 27, 2026 | 0 |
| Sep 26, 2026 | 0 |
| Sep 25, 2026 | 0 |
| Sep 24, 2026 | 0 |
| Sep 23, 2026 | 0 |
| Sep 22, 2026 | 0 |
| Sep 21, 2026 | 0 |
| Sep 20, 2026 | 0 |
| Sep 19, 2026 | 0 |
| Sep 18, 2026 | 0 |
| Sep 17, 2026 | 0 |
| Sep 16, 2026 | 0 |
| Sep 15, 2026 | 0 |
| Sep 14, 2026 | 0 |
| Sep 13, 2026 | 0 |
7−253 since Sep 19
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 7 |
| Dec 4, 2026 | 6 |
| Dec 3, 2026 | 6 |
| Dec 2, 2026 | 7 |
| Dec 1, 2026 | 7 |
| Nov 30, 2026 | 8 |
| Nov 29, 2026 | 12 |
| Nov 28, 2026 | 13 |
| Nov 27, 2026 | 12 |
| Nov 26, 2026 | 13 |
| Nov 25, 2026 | 12 |
| Nov 24, 2026 | 10 |
| Nov 23, 2026 | 11 |
| Nov 22, 2026 | 10 |
| Nov 21, 2026 | 12 |
| Nov 20, 2026 | 12 |
| Nov 19, 2026 | 15 |
| Nov 18, 2026 | 19 |
| Nov 17, 2026 | 21 |
| Nov 16, 2026 | 21 |
| Nov 15, 2026 | 21 |
| Nov 14, 2026 | 18 |
| Nov 13, 2026 | 19 |
| Nov 12, 2026 | 18 |
| Nov 11, 2026 | 13 |
| Nov 10, 2026 | 14 |
| Nov 9, 2026 | 16 |
| Nov 8, 2026 | 14 |
| Nov 7, 2026 | 25 |
| Nov 6, 2026 | 28 |
| Nov 5, 2026 | 26 |
| Nov 4, 2026 | 26 |
| Nov 3, 2026 | 23 |
| Nov 2, 2026 | 24 |
| Nov 1, 2026 | 24 |
| Oct 31, 2026 | 18 |
| Oct 30, 2026 | 22 |
| Oct 29, 2026 | 21 |
| Oct 28, 2026 | 21 |
| Oct 27, 2026 | 24 |
| Oct 26, 2026 | 22 |
| Oct 25, 2026 | 23 |
| Oct 24, 2026 | 23 |
| Oct 23, 2026 | 14 |
| Oct 22, 2026 | 19 |
| Oct 21, 2026 | 19 |
| Oct 20, 2026 | 17 |
| Oct 19, 2026 | 14 |
| Oct 18, 2026 | 14 |
| Oct 17, 2026 | 14 |
| Oct 16, 2026 | 16 |
| Oct 15, 2026 | 15 |
| Oct 14, 2026 | 15 |
| Oct 13, 2026 | 16 |
| Oct 12, 2026 | 17 |
| Oct 11, 2026 | 17 |
| Oct 10, 2026 | 14 |
| Oct 9, 2026 | 13 |
| Oct 8, 2026 | 10 |
| Oct 7, 2026 | 13 |
| Oct 6, 2026 | 13 |
| Oct 5, 2026 | 14 |
| Oct 4, 2026 | 14 |
| Oct 3, 2026 | 13 |
| Oct 2, 2026 | 16 |
| Oct 1, 2026 | 19 |
| Sep 30, 2026 | 30 |
| Sep 29, 2026 | 32 |
| Sep 28, 2026 | 39 |
| Sep 27, 2026 | 51 |
| Sep 26, 2026 | 84 |
| Sep 25, 2026 | 340 |
| Sep 24, 2026 | 336 |
| Sep 23, 2026 | 322 |
| Sep 22, 2026 | 318 |
| Sep 21, 2026 | 309 |
| Sep 20, 2026 | 294 |
| Sep 19, 2026 | 260 |
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/1372973491-root)<a href="https://payloaddirectory.dev/plugins/1372973491-root"><img src="https://payloaddirectory.dev/badge/1372973491-root.svg" alt="Payload Directory"></a>README
SSO-only authentication for Payload CMS 3 against Keycloak. No local
users, no passwords, no extra auth framework — one dependency (jose) on top of the standard OIDC
endpoints.
[!IMPORTANT] 🤖 This package is largely AI-generated.
keycloak — verifies a Keycloak access token (JWKS + issuer) taken from
Authorization: Bearer … or from the httpOnly session cookie, fetches /userinfo (cached per
token) and attaches its permissions claim to req.user. Users are created on first sight by
sub; keycloakSub, email and name are added to your auth collection unless it already
declares them. A lost first-login create race is retried as a lookup, so parallel first requests
do not turn into a silent 403.GET /api/auth/login → Keycloak → GET /api/auth/callback → cookies → back to /admin. The
/admin/login view redirects straight to Keycloak through a beforeLogin component./api/users/me reports the refresh token's exp, so Payload's inactivity timers follow
the Keycloak SSO session; POST /api/users/refresh-token and /api/users/logout are wired up
too. Bearer requests are never refreshed — the caller owns its own token.GET /api/auth/logout, which clears the cookies and hands
off to the Keycloak end-session endpoint with id_token_hint.authenticated, can('posts.edit'), withKeycloakAccess,
withKeycloakGlobalAccess, withAuth, plus permissionsOf(user) for ad-hoc checks.pnpm add payload-keycloak
import { buildConfig } from 'payload'
import {
authenticated,
can,
keycloakAuth,
withAuth,
withKeycloakAccess,
} from 'payload-keycloak'
const rules = { read: authenticated, write: can('posts.edit') }
export default buildConfig({
admin: { user: 'users' },
collections: withKeycloakAccess([Users, Posts], rules, ['users']),
endpoints: [{ path: '/report', method: 'get', handler: withAuth(reportHandler) }],
plugins: [
keycloakAuth({
url: process.env.KEYCLOAK_URL, // https://sso.example.com
realm: process.env.KEYCLOAK_REALM,
clientId: process.env.KEYCLOAK_CLIENT_ID, // public client, PKCE S256
serverURL: process.env.SERVER_URL, // https://app.example.com
basePath: process.env.BASE_PATH, // '' | '/sub-path'
}),
],
})
The auth collection keeps its own access; the plugin only sets auth.disableLocalStrategy, adds
the fields, the strategy and the me / refresh / afterLogout hooks.
Run payload generate:importmap after adding the plugin — the admin login and logout components are
resolved through your app's import map.
Public client, Standard flow, PKCE S256, with:
{serverURL}{basePath}/api/auth/callback{serverURL}{basePath}/adminRevoke Refresh Token must be OFF — see Limits.
Permissions are read from a userinfo claim as nested booleans:
{ "permissions": { "posts": { "edit": true } } }
can('posts.edit') passes when that path is exactly true. Point permissionsClaim at whatever
claim your realm populates; a user whose userinfo cannot be reached stays authenticated with empty
permissions.
| Option | Default | |
|---|---|---|
url, realm, clientId, serverURL | required | missing one throws at config build |
basePath | '' | Next.js basePath |
usersSlug | 'users' | auth collection |
scope | 'openid' | |
allowedOrigins | — | extra origins allowed to send the session cookie; serverURL is always allowed |
permissionsClaim | 'permissions' | userinfo claim holding nested boolean permissions |
userInfoTtl | 300 | seconds |
internalHosts | — | Host values of trusted in-network callers that read without a token as a shared user with no permissions; requires the ingress to route by its public host only |
messages | English | admin UI texts |
getKey | remote JWKS | JWTVerifyGetKey override for tests |
enabled | true |
Cookie names follow Payload's cookiePrefix: {prefix}-token (access, the cookie Payload itself
owns), {prefix}-refresh, {prefix}-id-token, and {prefix}-oidc-login during the login redirect.
Their domain / sameSite / secure attributes come from the auth collection's auth.cookies, so
the cookies this plugin writes and the ones Payload rewrites carry identical scope. secure
defaults to whether serverURL is https.
The plugin also forces auth.removeTokenFromResponses: the access token is a Keycloak credential
for the whole realm, so it stays in the httpOnly cookie and never reaches the me or
refresh-token JSON body.
/userinfo runs on every authenticated request and is aborted after 5 s; the token endpoint
(login, refresh) after 10 s./userinfo is cached per token for userInfoTtl, capped by the token's own exp./userinfo is cached for 15 s, but only a transport failure or a 5xx. A 401 is never
cached, so a revoked session loses its permissions on the very next request. It does not lose the
session itself: verification is offline (JWKS, no introspection), so the access token keeps
verifying until its own exp and the 401 is swallowed exactly like an outage — still
authenticated, no permissions. Reads survive until the token expires and the refresh then fails.aud is not validated; gate access with permissions instead.canSetHeaders, so a refresh that happens there cannot write the rotated cookies back and the
browser keeps re-sending the original refresh token; with rotation on, once the 60 s coalescing
window lapses the next render replays a spent token and bounces the user through Keycloak and
back — a flicker with lost form state, not a clean auth error. The coalescing window is
per-process, which is the other thing rotation would break at more than one replica.400 on an expired or
revoked refresh token). Payload returns the error message to the client for any status other
than 500, so message carries the status only; Keycloak's response body is attached to
KeycloakError.body instead, which stays server-side and reaches the log.500.*Url serverProp the plugin passes to an admin component is app-relative, without
basePath — the component prepends it. redirect() from next/navigation prepends basePath
on its own, so only components rendering a plain anchor add it explicitly. Prepending it in both
places gives a doubled prefix that is invisible when basePath is empty; dev/plugin.int.spec.ts
pins the rule against a non-empty one.The dev/ folder is a Payload app that loads the plugin from src/.
cp dev/.env.example dev/.env
pnpm install
pnpm dev # http://localhost:3000/admin
pnpm test:int # vitest, against an in-memory MongoDB and a fake IdP
pnpm test:e2e # playwright
pnpm generate:importmap regenerates dev/app/(payload)/admin/importMap.js after a component is
added or renamed.
MIT
payload zitadel plugin
Log in to the Mzinga admin through Zitadel or another OIDC provider using authorization code with PKCE
72608/wk11v?
oidc
OpenID Connect single sign-on for Payload using Authorization Code Flow with PKCE and native Payload sessions
65745/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 plugin oidc
Sign in to the Payload admin with any OpenID Connect provider
46159/wk36v2