WorkOS OAuth plugin for Payload CMS - adds Google OAuth login to your Payload admin panel.
- 🔐 Google OAuth authentication via WorkOS
- 🎨 Clean, customizable login button
- 🔒 Admin-only access control
- 🍪 JWT-based authentication with secure cookies
- ⚡ No session middleware required
- 🎯 Easy integration with existing Payload CMS projects
npm install payload-workos-oauth- A WorkOS account
- Google OAuth configured in your WorkOS dashboard
- Payload CMS v2.0.0 or higher
import { buildConfig } from "payload/config";
import { workosOAuthPlugin } from "payload-workos-oauth";
export default buildConfig({
// ... other config
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
plugins: [
workosOAuthPlugin({
clientID: process.env.WORKOS_CLIENT_ID || "",
clientSecret: process.env.WORKOS_API_KEY || "",
callbackURL: `${process.env.PAYLOAD_PUBLIC_SERVER_URL}/workos-oauth/callback`,
buttonLabel: "Sign in with Google",
}),
],
});WORKOS_CLIENT_ID=your_workos_client_id
WORKOS_API_KEY=your_workos_api_key
PAYLOAD_PUBLIC_SERVER_URL=https://your-domain.comIn your WorkOS dashboard:
- Add a redirect URI:
https://your-domain.com/workos-oauth/callback - Enable Google OAuth provider
- Copy your Client ID and API Key
Only users with role: 'admin' can log in via OAuth. Make sure your users collection has this field configured.
| Option | Type | Required | Description |
|---|---|---|---|
clientID |
string |
Yes | Your WorkOS Client ID |
clientSecret |
string |
Yes | Your WorkOS API Key |
callbackURL |
string |
Yes | The OAuth callback URL |
buttonLabel |
string |
No | Custom button text (default: "Sign in with Google") |
hideDefaultLogin |
boolean |
No | Hide the default email/password login form (default: false) |
authorizePath |
string |
No | Custom authorization endpoint path (default: "/workos-oauth/authorize") |
callbackPath |
string |
No | Custom callback endpoint path (default: "/workos-oauth/callback") |
successRedirect |
string |
No | Custom redirect after login (default: "/admin") |
components.Button |
React.ComponentType |
No | Custom button component |
If you want to show only the OAuth button and hide the default email/password login form, set hideDefaultLogin to true:
workosOAuthPlugin({
clientID: process.env.WORKOS_CLIENT_ID || "",
clientSecret: process.env.WORKOS_API_KEY || "",
callbackURL: `${process.env.PAYLOAD_PUBLIC_SERVER_URL}/workos-oauth/callback`,
buttonLabel: "Sign in with Google",
hideDefaultLogin: true, // This will hide the email/password form
});When hideDefaultLogin is enabled:
- Only the OAuth button will be displayed on the login page
- The default email/password form will be hidden
- The "OR" divider will not be shown
You can provide your own button component:
import CustomButton from "./CustomButton";
workosOAuthPlugin({
// ... other options
components: {
Button: CustomButton,
},
});Your custom button component will receive these props:
interface ButtonProps {
authorizePath: string;
buttonLabel: string;
}- User clicks "Sign in with Google" on the Payload admin login page
- User is redirected to WorkOS/Google OAuth
- User authenticates with Google
- WorkOS redirects back to your callback URL with an authorization code
- Plugin exchanges the code for user profile information
- Plugin finds the user in Payload by email (must have
role: 'admin') - Plugin generates a JWT token and sets a secure cookie
- User is redirected to the admin dashboard
- Only users with
role: 'admin'can authenticate via OAuth - JWT tokens are signed with your Payload secret
- Cookies are set with
httpOnlyflag for security - All server-side modules are properly isolated from client bundle
MIT
Bibek Thapa
Contributions are welcome! Please open an issue or submit a pull request.