2.1.1 • Published 4 months ago

payload-plugin-oauth v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

oAuth plugin for Payload CMS

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({
      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,
      callbackURL: process.env.OAUTH_CALLBACK_ENDPOINT,
      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,
        }
      },
    }),
  ],
  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.

2.2.0-rc.0

4 months ago

2.2.0-rc.1

4 months ago

2.1.1

5 months ago

2.1.0

5 months ago

1.0.1

6 months ago

1.0.0

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

0.3.0

1 year ago

0.3.1

1 year ago

0.2.0

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago