# payload-plugin-oauth

Latest version **2.2.1** (published 2026-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install payload-plugin-oauth
pnpm add payload-plugin-oauth
yarn add payload-plugin-oauth
bun add payload-plugin-oauth
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2026-05-21 |
| First published | 2022-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 23.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 112 |
| Author | Thomas Ghysels |
| Maintainers | thgh |

## Links

- npm: https://www.npmjs.com/package/payload-plugin-oauth
- Repository: https://github.com/thgh/payload-plugin-oauth
- Issues: https://github.com/thgh/payload-plugin-oauth/issues
- npm.io page: https://npm.io/package/payload-plugin-oauth

## Dependencies (5)

- [debug](https://npm.io/package/debug.md) ^4
- [@bothrs/util](https://npm.io/package/@bothrs/util.md) ^3
- [connect-mongo](https://npm.io/package/connect-mongo.md) ^4
- [express-session](https://npm.io/package/express-session.md) ^1
- [passport-oauth2](https://npm.io/package/passport-oauth2.md) ^1

## Recent versions

- 2.2.1 (latest) — 2026-05-21
- 2.2.0-rc.1 (next) — 2024-01-02
- 2.2.0 — 2024-06-21
- 2.2.0-rc.0 — 2024-01-02
- 2.1.1 — 2023-12-15
- 2.0.1 — 2023-10-24
- 1.0.1 — 2023-10-24
- 1.0.0 — 2023-10-24
- 2.0.0 — 2023-10-24
- 0.3.1 — 2023-04-06
- 0.3.0 — 2023-03-31
- 0.2.0 — 2022-11-14
- 0.1.7 — 2022-11-14
- 0.1.6 — 2022-11-05
- 0.1.5 — 2022-11-05
- … 1 more at https://npm.io/package/payload-plugin-oauth/versions

## README

# oAuth plugin for Payload CMS

<a href="LICENSE">
  <img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="Software License" />
</a>
<a href="https://github.com/thgh/payload-plugin-oauth/issues">
  <img src="https://img.shields.io/github/issues/thgh/payload-plugin-oauth.svg" alt="Issues" />
</a>
<a href="https://npmjs.org/package/payload-plugin-oauth">
  <img src="https://img.shields.io/npm/v/payload-plugin-oauth.svg?style=flat-squar" alt="NPM" />
</a>

## 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

```js
// 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](CHANGELOG.md) 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

- [Thomas Ghysels](https://github.com/thgh)
- [Wilson Le](https://github.com/wilsonle)
- [All Contributors][link-contributors]

## License

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

[link-contributors]: ../../contributors

---
_Source: https://npm.io/package/payload-plugin-oauth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
