Adds a Sign in with GitHub button to the Payload admin login page using a GitHub App user authorization flow with state and PKCE. It verifies the GitHub email, creates or links a Payload user, and issues a session through a github-jwt strategy. Requires Payload 4 beta, React 19, a recent Node version, and a users collection with a singular role select field.
GitHub App login for the Payload CMS admin
Installation
npm i @larssont/payload-github-auth0
Stars
0
Forks
2
Open Issues
Today
Last Updated
27
Weekly Downloads
v0.1.0
npm Version
180.3 KB
Unpacked Size
2
Dependencies
00 since Nov 8
| 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 |
27+27 since Nov 15
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 27 |
| Dec 4, 2026 | 26 |
| Dec 3, 2026 | 27 |
| Dec 2, 2026 | 25 |
| Dec 1, 2026 | 26 |
| Nov 30, 2026 | 29 |
| Nov 29, 2026 | 26 |
| Nov 28, 2026 | 25 |
| Nov 27, 2026 | 27 |
| Nov 26, 2026 | 35 |
| Nov 25, 2026 | 34 |
| Nov 24, 2026 | 44 |
| Nov 23, 2026 | 339 |
| Nov 22, 2026 | 333 |
| Nov 21, 2026 | 331 |
| Nov 20, 2026 | 328 |
| Nov 19, 2026 | 317 |
| Nov 18, 2026 | 315 |
| Nov 17, 2026 | 300 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
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/1458057442-root)<a href="https://payloaddirectory.dev/plugins/1458057442-root"><img src="https://payloaddirectory.dev/badge/1458057442-root.svg" alt="Payload Directory"></a>README
GitHub App login for the Payload CMS admin. The plugin adds a “Sign in with GitHub” button to the login page, verifies the user’s GitHub email, creates or links the Payload user, and mints a normal Payload session. It runs GitHub-only by default; set allowPasswordLogin: true to keep the local email/password strategy.
Status:
0.1.0, Payload 4 beta. ESM-only, Node>=26.13.1.
org/team-slug.defaultRole and refuses deniedRoles.github-jwt session strategy with logout revocation and refresh extension.>=26.13.1.role select field.The plugin expects role to be a single value, not a roles array. The configured defaultRole must be one of the field’s options.
pnpm add @larssont/payload-github-auth
After installing:
pnpm payload generate:importmap
pnpm payload generate:types
The plugin adds a login button component; the admin import map must include it. Import the button styles in the CSS file your admin already uses:
@import "@larssont/payload-github-auth/client.css";
In production, create and run a Payload migration for the new email, sessions, and github_id fields. If you disable the local strategy, the same migration drops Payload’s password fields. In development, Payload’s schema push handles it.
import { buildConfig } from "payload"
import { githubAuthPlugin, parseAdminEmails } from "@larssont/payload-github-auth"
export default buildConfig({
admin: { user: "users" },
collections: [Users],
plugins: [
githubAuthPlugin({
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
access: { email: parseAdminEmails(process.env.GITHUB_EMAILS) },
defaultRole: "editor",
serverUrl: process.env.PAYLOAD_PUBLIC_SERVER_URL!,
}),
],
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
})
A minimal users collection:
import type { CollectionConfig } from "payload"
export const Users: CollectionConfig = {
slug: "users",
auth: true,
fields: [
{
name: "role",
type: "select",
required: true,
options: [
{ label: "Admin", value: "admin" },
{ label: "Editor", value: "editor" },
],
},
],
}
The plugin adds the email, sessions, and github_id fields and installs the github-jwt strategy. The local email/password strategy is disabled unless allowPasswordLogin: true. When enabled, GitHub-created users receive a random password hash they never use; password login remains available for users who set a password.
Create a GitHub App. Pick the prefilled registration link that matches your access rules; both set the name, homepage, public=false, and webhooks off:
org or team rules: Create the GitHub App with Members: ReadChange the name if GitHub says it is taken. You still create the app, set its redirect URI, and generate the client secret yourself; the links only prefill the form.
# Email-only login
https://github.com/settings/apps/new?name=payload-github-auth&description=GitHub%20App%20login%20for%20the%20Payload%20CMS%20admin&url=https://github.com/larssont/payload-github-auth&public=false&webhook_active=false&emails=read
# org or team rules
https://github.com/settings/apps/new?name=payload-github-auth&description=GitHub%20App%20login%20for%20the%20Payload%20CMS%20admin&url=https://github.com/larssont/payload-github-auth&public=false&webhook_active=false&emails=read&members=read
Set the Redirect URI to your app's callback URL. The port depends on where Payload runs, so use your own:
<serverUrl>/api/<usersSlug>/oauth/github/callback
With the default usersSlug:
<serverUrl>/api/users/oauth/github/callback
GitHub Apps support up to 10 callback URLs, so add localhost alongside production:
http://localhost:3000/api/users/oauth/github/callback
Configure these permissions:
| Permission | Level | When |
|---|---|---|
| Account → Email addresses | Read | Always; /user/emails needs it. |
| Organization → Members | Read | Only when you use org or team access rules. |
Install the app on the account or organization:
org or team rules, install the app on that organization with Members: read. The plugin uses the user access token to read /user/orgs and the team membership endpoint; the app must be installed on the org for that token to see it.Generate a client secret and set GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET; put the allowed addresses in GITHUB_EMAILS (or pass them directly to access). The plugin does not need the app’s private key; it uses the user authorization flow, not installation tokens.
Expire user authorization tokens does not affect the plugin. The token is used only during the callback and then discarded, so its lifetime never matters. The plugin sends scope=offline_access, which asks GitHub for an expiring token and a refresh token; it ignores the refresh token. Either setting works.
Webhooks are not used. You do not need a tunnel for local development; the GitHub authorization redirect goes straight to localhost.
access is required. It can be one rule, a shorthand list, or an explicit rule set:
// one rule
access: { email: parseAdminEmails(process.env.GITHUB_EMAILS) }
// any of these grants access (the shorthand defaults to match: "any")
access: [
{ email: parseAdminEmails(process.env.GITHUB_EMAILS) },
{ team: "acme/engineering" },
]
// both must pass
access: {
match: "all",
rules: [
{ email: (email) => email.endsWith("@acme.com") },
{ org: "acme" },
],
}
A rule is exactly one of:
| Rule | Matches |
|---|---|
{ email } | A verified GitHub email; a string list or a function. |
{ org } | An organization login; a string or string list. |
{ team } | A team as org/team-slug; a string or string list. |
match is "any" (default) or "all". Rules are evaluated after a verified email is selected (the primary verified address is preferred) and before a user is created or linked. Org rules use /user/orgs. Team rules use GET /orgs/{org}/teams/{team_slug}/memberships/{username}, which includes inherited child-team membership; that is one request per configured team rule. The GitHub App must be installed on the org with Members: read.
Access is checked at login. An existing session is not re-checked when someone leaves an org or team; it survives until the session expires or is revoked. Use a short tokenExpiration and disable refresh if you need a short revocation window.
The rate limiter and the login notification email use ipAddress:
ipAddress: {
headers: ["x-forwarded-for"], // read in order
trustedProxies: [], // CIDRs to skip in an XFF chain
ipv6Subnet: 64, // group IPv6 clients by /64
}
x-real-ip or cf-connecting-ip is used directly.x-forwarded-for, the plugin walks the chain from the right and skips trustedProxies; the first untrusted address is the client.trustedProxies, or no valid address is found, all clients share one rate-limit bucket ("unknown").ipv6Subnet; /64 is the default, /56 for residential ISP allocations, /128 only for controlled networks.Railway (the edge overwrites X-Real-IP):
ipAddress: { headers: ["x-real-ip"], ipv6Subnet: 64 }
Railway behind Cloudflare:
ipAddress: { headers: ["cf-connecting-ip"], ipv6Subnet: 64 }
Self-hosted nginx with a static proxy CIDR:
ipAddress: { headers: ["x-forwarded-for"], trustedProxies: ["10.0.0.0/8"], ipv6Subnet: 64 }
Direct clients, no proxy:
ipAddress: {
headers: []
} // one shared bucket
The plugin cannot read the socket address (Payload’s request is a web Request), so direct connections need a header set by your server or proxy if you want per-client limits.
| Option | Type | Description |
|---|---|---|
clientId | string | GitHub App client ID. |
clientSecret | string | GitHub App client secret. |
usersSlug | string | Auth collection slug. Defaults to users. |
adminRoute | string | Admin route used for the login redirect and the completion page. Defaults to config.routes.admin, then /admin. Must be a path, not a URL. |
serverUrl | string | Public CMS origin. Defaults to config.serverURL; one of them is required. |
access | GithubAccessConfig | Required. One rule, a list, or { match, rules }. See above. |
defaultRole | string | Required. Role assigned to a new GitHub user. |
deniedRoles | string[] | Roles refused for GitHub sign-in. Defaults to []. |
githubClient | GithubClient | Optional GitHub transport for tests or a custom HTTP client. Custom clients must implement fetchTeamMembership and return login from fetchUser. |
onLogin | (event) => Promise<void> | Override the default login notification email. |
ipAddress | IpAddressOptions | Client IP source for rate limiting and the login email. Defaults to headers: ["x-forwarded-for"], trustedProxies: [], ipv6Subnet: 64. |
rateLimit | { windowMs?, max? } | false | Per-process login rate limit. Defaults to 10 requests per 15 minutes. Uses ipAddress. |
appName | string | Name used in the login email. Defaults to CMS. |
allowPasswordLogin | boolean | Keep the local email/password strategy. Defaults to false. When enabled, GitHub-created users get a random, unusable password hash. |
access has no development bypass. An empty rule set is rejected at boot, and defaultRole cannot be in deniedRoles.
Payload has generic access control, but it has no built-in role system and does not know that this plugin uses a singular role field. createGithubAuthAccess is an optional convenience that encodes the plugin’s assumptions:
import { createGithubAuthAccess } from "@larssont/payload-github-auth"
const { adminOnly, adminField, selfOrAdmin } = createGithubAuthAccess({
adminRole: "admin",
})
adminOnly — collection-level Access; returns true only for admins. Use it for create/delete or an admin-only collection.adminField — field-level FieldAccess; returns true only for admins. Use it on role (and other sensitive fields) for access.create/access.update; non-admin writes are stripped. Add access.read if non-admins should not see the field.selfOrAdmin — collection-level Access; returns { id: { equals: req.user.id } } for a signed-in non-admin, true for an admin, and false for anonymous. Use it on read/update/delete; not on create, which expects a boolean rather than a where.Example:
export const Users: CollectionConfig = {
slug: "users",
auth: true,
access: {
read: selfOrAdmin,
update: selfOrAdmin,
create: adminOnly,
delete: adminOnly,
},
fields: [
{
name: "role",
type: "select",
required: true,
options: ["admin", "editor"],
access: {
create: adminField,
update: adminField,
},
},
],
}
selfOrAdmin restricts which documents a user can touch, not which fields. Pair it with adminField on role and any other sensitive field such as email; otherwise a user can edit their own document's unprotected fields.
Why import it? It saves you from reimplementing the same checks and, more importantly, from forgetting to protect the role field. Without field-level protection, a user who can update their own profile may be able to change their role. The helpers are not required; write your own if you use a roles array or a different role model.
HttpOnly, SameSite=Lax, host-only, and Secure in production.@larssont/payload-github-auth/client.css), not an inline <style> tag, so a strict style-src can work if the rest of the admin does not need inline styles.authVersion, and the Payload secret; the session id must still exist on the user.POST /api/<usersSlug>/logout?allSessions=true clears every session for the user; the admin UI does not expose that flag, and the server-function logout path does not pass it.allowPasswordLogin: false (the default), no password or hash is stored for GitHub users. With true, Payload’s local strategy requires a password on create; the plugin generates a random one and Payload stores only its hash, which the user never knows.Email addresses: read, Members: read) instead of OAuth scopes. The plugin sends offline_access and discards the user token, and any refresh token, after login.Host responsibilities: use HTTPS, set a CSP and security headers, keep Payload and dependencies patched, protect payload.secret and the GitHub App client secret, enforce GitHub 2FA/org policy where needed, and protect the role field and users collection access.
github_id can be linked to a GitHub account with the same verified email. The relink guard protects users that already have a github_id.sessions array; concurrent login/logout can lose or revive a session. Payload’s own session helpers use the same pattern.allSessions=true is honored on REST logout only; the admin UI does not expose it and the server-function path does not pass it.allowPasswordLogin: true keeps the password attack surface and stores a random hash for GitHub users.__Host- cookies; Payload shares cookiePrefix with its language cookie, which is not set with Secure.GithubClient implementations must implement fetchTeamMembership and return login from fetchUser.The recipes wrap pnpm; just is the task runner.
| Command | What it does |
|---|---|
just setup | Install dependencies, create dev/.env, and generate dev files. |
just dev | Start the dev app at http://localhost:3000. |
just check | Run Biome, Knip, and tsc. |
just fix | Apply Biome’s safe lint, format, and import fixes. |
just test | Run unit tests. Pass a file or pattern to narrow the run. |
just test-integration | Run integration tests against a real Payload + SQLite instance. |
just test-coverage | Run unit tests with coverage. |
just build | Build the package into dist/. |
just package | Build, then check the packed package with publint and attw. |
just generate | Regenerate the Payload import map and types. |
just clean | Remove dist/. |
just ci | Run the checks CI runs. |
just publish | Publish to npm, tag v<version>, and push the tag. |
just setup and just dev create dev/.env from dev/.env.example and generate the Payload import map and types. The generated _payload files are not tracked; payload-types.ts and routeTree.gen.ts are tracked so tsc works on a fresh checkout.
Local development has no proxy, so the default x-forwarded-for header is absent and the rate limiter uses one shared bucket. The dev config sets rateLimit: false; set it back if you want to exercise the limiter locally.
Add the dev callback URL to the GitHub App:
http://localhost:3000/api/users/oauth/github/callback
just publish requires a clean working tree and an npm login. It runs the checks, publishes, tags v<version>, and pushes the tag.
Topics
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
payload zitadel plugin
Log in to the Mzinga admin through Zitadel or another OIDC provider using authorization code with PKCE
72608/wk11v?
payload simple social login
Google and Microsoft social login for the Payload admin panel and auth collections
7119/wk3v3
payload auth
Replace Payload's built-in auth with Better Auth for a shared admin and frontend session
7021.0k/wk349v3
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