chatgpt-plugin-clerk-auth
chatgpt-plugin-clerk-auth copied to clipboard
ChatGPT plugin example using Cloudflare Workers and Clerk OAuth2 backend.
ChatGPT plugin with Clerk OAuth2 backend
This is an example implementation of ChatGPT plugin running on Cloudflare Workers with Clerk OAuth2 backend.
Features
- [x] Authenticate users with Clerk during plugin installation
- [x] Authenticated plugin API calls
- [x] OpenAPI schema generation (using cloudflare/itty-router-openapi)
Plugin routes
- [x]
/user
Get user's details - [x]
/user/send-email
Send email to signed in user (using Sendgrid, additional config needed)
Setup
Sign up for Clerk
- Sign up for Clerk account
- Create Clerk application
Create OAuth application
- Get API Key (Developers -> API Keys -> Secret keys), you will need it later
- Create OAuth application, use API key you got from previous steps
- Use any URL (e.g.
https://example.com
) as callback URL for now, you will change it later. - Set
public
tofalse
- Use any URL (e.g.
- Note the response, you will need following later
-
client_id
-
client_secret
- base URL of your OAuth2 Clerk instance (e.g.
https://fond-tuna-4.clerk.accounts.dev
)
-
Deploy Workers application
- Edit src/index.ts and set following
-
clerkBaseUrl
to the base URL you got from previous steps
-
-
npm install
-
npm run deploy
- Note the URL of your Workers application, you will need it later
Configure ChatGPT plugin
- Install new ChatGPT plugin
- Fill in Client ID and Client Secret you got from previous steps
- Get the verification token and set it as
pluginVerificationToken
in src/index.ts - Redeploy Workers application (
npm run deploy
) - Click
Verify tokens
- Install the plugin
- Click
Log in with Plugin with Clerk
- You will get 400 error, it's OK - you need to change callback URL in OAuth application
- Grab the URL from the request URL, you can get decoded one from the network tab
- Edit (PATCH) OAuth application and set the URL as callback URL
- Close the tab and try to log in again
- Grab the URL from the request URL, you can get decoded one from the network tab
Write your own plugin routes
- Edit src/index.ts and add your own route handlers
- Redeploy Workers application (
npm run deploy
)