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
import { oAuthPlugin } from 'payload-plugin-oauth'
export default buildConfig({
serverURL: process.env.SERVER_URL,
collections: [Users],
plugins: [
oAuthPlugin({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
authorizationURL: process.env.OAUTH_SERVER + '/oauth/authorize',
tokenURL: process.env.OAUTH_SERVER + '/oauth/token',
callbackURL: process.env.SERVER_URL + '/oauth2/callback',
scope: 'basic',
async userinfo(accessToken) {
const { data: user } = await axios.get(OAUTH_SERVER + '/oauth/me', {
params: { access_token: accessToken },
})
return {
sub: user.ID,
name: user.display_name || user.user_nicename || 'Naamloos',
email: user.user_email,
role: user.capabilities?.administrator ? 'admin' : 'user',
}
},
}),
],
})
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Contributions and feedback are very welcome.
To get it running:
- Clone the project.
npm install
npm run build
Credits
License
The MIT License (MIT). Please see License File for more information.