thgh

payload plugin oauth

by thgh
Authentication & SSO
v2
^2
MIT

Overview

Summary generated from the README

Adds OAuth2 sign-in to a Payload site by configuring passport-oauth2 and mounting authorize and callback routes. It also adds a sign-in button to the login page. The plugin is registered once per provider with unique paths, and a userinfo function maps the provider's response to a user. Version 2 targets Payload v2 and version 1 targets Payload v1.

Features

  • Configures passport-oauth2 with client ID, secret, authorization and token URLs
  • Mounts authorize and callback routes
  • Adds a sign-in button with a custom label to the login page
  • Supports multiple providers by registering the plugin several times with unique paths
  • Custom userinfo function maps the provider response to a user

Use cases

  • Let admin users sign in through an existing OAuth2 identity provider
  • Offer several OAuth providers side by side on the Payload login page

From the author

Add oAuth sign in to your Payload CMS site

Installation

npm i payload-plugin-oauth

113

Stars

15

Forks

12

Open Issues

6 months ago

Last Updated

70

Weekly Downloads

v2.2.1

npm Version

23.7 KB

Unpacked Size

5

Dependencies

GitHub stars

113+1 since Sep 7

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

70−7 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202670
Dec 5, 202639
Dec 4, 202637
Dec 3, 202642
Dec 2, 202647
Dec 1, 202667
Nov 30, 202682
Nov 29, 202686
Nov 28, 202691
Nov 27, 202690
Nov 26, 202690
Nov 25, 202682
Nov 24, 202667
Nov 23, 202654
Nov 22, 202647
Nov 21, 202641
Nov 20, 202643
Nov 19, 202636
Nov 18, 202632
Nov 17, 202626
Nov 16, 202621
Nov 15, 202629
Nov 14, 202633
Nov 13, 202632
Nov 12, 202638
Nov 11, 202639
Nov 10, 202645
Nov 9, 202646
Nov 8, 202636
Nov 7, 202642
Nov 6, 202635
Nov 5, 202629
Nov 4, 202628
Nov 3, 202628
Nov 2, 202635
Nov 1, 202636
Oct 31, 202637
Oct 30, 202656
Oct 29, 202651
Oct 28, 202648
Oct 27, 202654
Oct 26, 202653
Oct 25, 202660
Oct 24, 202666
Oct 23, 202647
Oct 22, 202666
Oct 21, 202682
Oct 20, 202681
Oct 19, 202678
Oct 18, 202692
Oct 17, 202686
Oct 16, 202696
Oct 15, 202686
Oct 14, 2026105
Oct 13, 2026103
Oct 12, 2026102
Oct 11, 202683
Oct 10, 202678
Oct 9, 202674
Oct 8, 202675
Oct 7, 202648
Oct 6, 202642
Oct 5, 202641
Oct 4, 202651
Oct 3, 202654
Oct 2, 202657
Oct 1, 202654
Sep 30, 202649
Sep 29, 202666
Sep 28, 202668
Sep 27, 202659
Sep 26, 202669
Sep 25, 202669
Sep 24, 202672
Sep 23, 202680
Sep 22, 202677
Sep 21, 202676
Sep 20, 202677
Sep 19, 202663
Sep 18, 202654
Sep 17, 202658
Sep 16, 202656
Sep 15, 202639
Sep 14, 202638
Sep 13, 202640
Sep 12, 202637
Sep 11, 202651
Sep 10, 202645
Sep 9, 202655
Sep 8, 202659
Sep 7, 202677

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

Health Score

49/100Fair

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/562098618-root.svg)](https://payloaddirectory.dev/plugins/562098618-root)
HTML
<a href="https://payloaddirectory.dev/plugins/562098618-root"><img src="https://payloaddirectory.dev/badge/562098618-root.svg" alt="Payload Directory"></a>
Updated May 21, 2026Created Nov 5, 2022Published May 21, 2026

README

oAuth plugin for Payload CMS

Software License Issues NPM

Features

  • Configures passport-oauth2
  • Mounts authorize & callback route
  • Adds sign in button on login page

Installation

Payload v2

npm install payload-plugin-oauth@^2
# or
yarn add payload-plugin-oauth@^2

Payload v1

npm install payload-plugin-oauth@^1
# or
yarn add payload-plugin-oauth@^1

Usage

// payload.config.ts
import path from 'path'

import { webpackBundler } from '@payloadcms/bundler-webpack'
import { mongooseAdapter } from '@payloadcms/db-mongodb'
import { slateEditor } from '@payloadcms/richtext-slate'
import axios from 'axios'
import { oAuthPlugin } from 'payload-plugin-oauth'
import { buildConfig } from 'payload/config'
import Users from './collections/Users'

export default buildConfig({
  admin: {
    user: Users.slug,
    bundler: webpackBundler(),
  },
  editor: slateEditor({}),
  collections: [Users],
  typescript: {
    outputFile: path.resolve(__dirname, 'payload-types.ts'),
  },
  graphQL: {
    schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
  },
  plugins: [
    payloadCloud(),
    oAuthPlugin({
      buttonLabel: 'Sign in with oAuth',
      databaseUri: process.env.DATABASE_URI,
      clientID: process.env.OAUTH_CLIENT_ID,
      clientSecret: process.env.OAUTH_CLIENT_SECRET,
      authorizationURL: process.env.OAUTH_AUTH_ENDPOINT,
      tokenURL: process.env.OAUTH_TOKEN_ENDPOINT,
      authorizePath: '/oauth/authorize1',
      callbackURL: process.env.ORIGIN + '/oauth/callback1',
      async userinfo(accessToken) {
        const { data: user } = await axios.get(
          process.env.OAUTH_USERINFO_ENDPOINT,
          { headers: { Authorization: `Bearer ${accessToken}` } }
        )
        return {
          sub: user.ID,
          username: user.preferred_username,
        }
      },
    }),
    // Another oAuth provider
    oAuthPlugin({
      buttonLabel: 'Sign in with Alternative',
      // These paths must be unique per provider
      authorizePath: '/oauth/authorize2',
      callbackURL: process.env.ORIGIN + '/oauth/callback2',

      ...rest,
    }),
  ],
  db: mongooseAdapter({
    url: process.env.DATABASE_URI,
  }),
})

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Contributions and feedback are very welcome.

To get it running:

  1. Clone the project.
  2. npm install
  3. npm run build

Publishing process

  1. Run npm run fix
  2. Run npm version minor
  3. Push to Github and let CI publish to NPM

Credits

License

The MIT License (MIT). Please see License File for more information.

Similar plugins