https://github.com/thgh/payload-plugin-oauth
Add oAuth sign in to your Payload CMS site
https://github.com/thgh/payload-plugin-oauth
payload payload-plugin payloadcms
Last synced: 10 months ago
JSON representation
Add oAuth sign in to your Payload CMS site
- Host: GitHub
- URL: https://github.com/thgh/payload-plugin-oauth
- Owner: thgh
- License: mit
- Created: 2022-11-05T10:01:02.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-02T23:25:08.000Z (over 2 years ago)
- Last Synced: 2024-04-25T23:04:56.134Z (about 2 years ago)
- Topics: payload, payload-plugin, payloadcms
- Language: TypeScript
- Homepage:
- Size: 408 KB
- Stars: 60
- Watchers: 3
- Forks: 11
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```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