Skip to content

Commit

Permalink
feat: fork payload-plugin-oauth to manage dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlstrm committed Jul 15, 2024
1 parent d75c008 commit b5e10ef
Show file tree
Hide file tree
Showing 10 changed files with 1,028 additions and 1,039 deletions.
3 changes: 2 additions & 1 deletion apps/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"nanoid": "^3.3.7",
"papaparse": "^5.4.1",
"payload": "^2.22.0",
"payload-plugin-oauth": "^2.1.1"
"payload-plugin-oauth": "workspace:*"
},
"devDependencies": {
"@tietokilta/cms-types": "workspace:*",
Expand All @@ -43,6 +43,7 @@
"@types/react": "^18.3.3",
"copyfiles": "^2.4.1",
"eslint": "^8.57.0",
"mongodb": "^4.17.1",
"react": "^18.3.1",
"tsx": "^4.15.6",
"typescript": "^5.5.2"
Expand Down
15 changes: 0 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
},
"packageExtensions": {
"[email protected]": {
"dependencies": {
"@aws-sdk/credential-providers": "3.575.0"
}
},
"payload-plugin-oauth@^2.1.1": {
"dependencies": {
"passport": "^0.6"
},
"peerDependencies": {
"@types/passport-oauth2": "^1.4.15"
}
}
}
}
}
21 changes: 21 additions & 0 deletions packages/payload-plugin-oauth/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Thomas Ghysels

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
132 changes: 132 additions & 0 deletions packages/payload-plugin-oauth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# 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
57 changes: 57 additions & 0 deletions packages/payload-plugin-oauth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "payload-plugin-oauth",
"version": "2.2.0-rc.1",
"homepage": "https://github.com/thgh/payload-plugin-oauth",
"bugs": {
"url": "https://github.com/thgh/payload-plugin-oauth/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/thgh/payload-plugin-oauth"
},
"license": "MIT",
"author": "Thomas Ghysels <[email protected]>",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./dist/*": "./dist/*"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"fix": "pnpm prettier src --write",
"test": "echo 'no tests'"
},
"dependencies": {
"connect-mongo": "^4",
"debug": "^4",
"express-session": "^1",
"passport-oauth2": "^1"
},
"devDependencies": {
"@tietokilta/config-typescript": "workspace:*",
"@types/debug": "^4",
"@types/express-session": "^1",
"@types/jsonwebtoken": "^9.0.1",
"@types/passport": "^1",
"@types/passport-oauth2": "^1",
"@types/react": "^18.0.33",
"payload": "^2",
"react": "^18",
"typescript": "^5.5.2"
},
"peerDependencies": {
"@payloadcms/db-mongodb": "^1",
"mongodb": "^4.17.1",
"passport": "^0.6",
"payload": "^2",
"react": "^18"
}
}
13 changes: 13 additions & 0 deletions packages/payload-plugin-oauth/src/OAuthButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Button from 'payload/dist/admin/components/elements/Button'
import React from 'react'
import { ButtonProps } from './types'

export default function OAuthButton(props: ButtonProps) {
return (
<div style={{ marginBottom: 40 }}>
<Button el="anchor" url={props.authorizePath}>
{props.buttonLabel}
</Button>
</div>
)
}
Loading

0 comments on commit b5e10ef

Please sign in to comment.