Adds OAuth sign-in to a Payload CMS site by configuring passport-oauth2 and mounting authorize and callback routes. It also adds a sign-in button to the login page. Multiple providers can be added by registering the plugin several times with unique paths. Version 2 targets Payload v2 with the MongoDB adapter.
Add oAuth sign in to your Payload CMS site
Installation
npm i payload-plugin-oauth112
Stars
15
Forks
12
Open Issues
5 months ago
Last Updated
0
Weekly Downloads
v2.2.1
npm Version
23.7 KB
Unpacked Size
5
Dependencies
Trends appear after 7 days of data. Daily snapshots have not started yet.
Trends appear after 7 days of data. Daily snapshots have not started yet.
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/562098618-root)<a href="https://payloaddirectory.dev/plugins/562098618-root"><img src="https://payloaddirectory.dev/badge/562098618-root.svg" alt="Payload Directory"></a>README
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
// 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,
}),
})
Please see CHANGELOG for more information what has changed recently.
Contributions and feedback are very welcome.
To get it running:
npm installnpm run buildnpm run fixnpm version minorThe MIT License (MIT). Please see License File for more information.
Topics
payload better auth
Better Auth database adapter and plugins that replace Payload's local auth strategy
700/wk74v3
payload simple social login
Google and Microsoft Entra ID social login for the Payload admin panel and auth collections
650/wk3v3
payload auth
Replaces Payload's built-in auth with Better Auth, sharing one session between the admin panel and your app
590/wk344v3
payload oauth2
Generic OAuth2 sign-in for Payload auth collections with any OAuth2 provider
570/wk198v3
payload authjs
Use Auth.js 5 providers to sign in and authenticate users in Payload CMS 3
560/wk207v3
payload keycloak
Keycloak SSO login for the Payload admin using OIDC with PKCE, silent refresh and permission-based access helpers
500/wk0v3