OAuth Integration
Guides, route-group overviews, and live schema entry points for the Plexichat backend.
OAuth integration guide
Note: Plexichat does not currently operate as an OAuth 2.0 authorization server. There are no
/oauth2/authorizeor/oauth2/tokenendpoints, so Plexichat cannot issue OAuth 2.0 access tokens to third-party apps, support "Add to server" bot authorization URLs, or accept authorization-code or refresh-token grants. Everything in the roadmap section is a design sketch for a future release. What is available today is inbound identity-provider sign-in with Google, GitHub, Microsoft, or GitLab. See Inbound provider sign-in.
Overview
OAuth integration with Plexichat means one of two things:
- Inbound identity-provider sign-in (implemented). Plexichat acts as an OAuth 2.0 client and lets users sign in with an external provider (Google, GitHub, Microsoft, or GitLab).
- OAuth 2.0 authorization server (not implemented). Plexichat would act as the authorization server and issue tokens to third-party apps. This does not exist yet.
Inbound provider sign-in (implemented)
Users sign in through an external provider. Plexichat performs the code-to-token exchange internally, so your app never handles provider tokens.
GET /api/v1/auth/oauth/{provider}/login → { url, auth_url, state }
POST /api/v1/auth/oauth/{provider}/callback → LoginResponse
Replace {provider} with google, github, microsoft, or gitlab. For full request and response shapes, see the authentication API.
Plexichat uses PKCE toward the provider when enabled. The state value is single-use and short-lived (10 minutes). Mark it used after you verify it on callback.
Google setup
Create an OAuth 2.0 client in Google Cloud Console.
Add the authorized redirect URI that matches your deployment's callback route (
/api/v1/auth/oauth/google/callback).Add credentials to
config/config.yaml:oauth: google: client_id: "your_google_client_id" client_secret: "your_google_client_secret"
GitHub setup
- Create an OAuth app in GitHub Developer Settings.
- Configure the callback URL for your deployment.
- Add credentials under
oauth.githubusing the same keys as the Google example.
Microsoft setup
- Register an app in Microsoft Entra ID (Azure portal).
- Configure the redirect URI for your deployment.
- Add credentials under
oauth.microsoft.
The exact redirect URI depends on how your instance exposes /api/v1/auth/oauth/{provider}/callback. Configure the same URI at the provider.
Roadmap: Plexichat as an OAuth 2.0 authorization server
The following capabilities have no implementation and no routes today. Do not target them; requests fail because the routes do not exist.
GET /oauth2/authorizeauthorization endpoint with a consent screenPOST /oauth2/tokentoken endpoint (authorization-code grant, refresh grant)- PKCE (S256) for public clients
- Bot or "add to server" authorization flows (
scope=bot&permissions=...) - Enforcement of scopes such as
identify,email,guilds,guilds.join, andbot
Until this work ships, any guide that shows live examples against these endpoints is out of date.
Custom inbound provider
To add another inbound provider for sign-in, follow the pattern of the built-in handlers in src/api/routes/auth/oauth.py:
- Implement a handler that builds the authorization URL, exchanges the code, and fetches user info.
- Register
GET /api/v1/auth/oauth/{provider}/loginandPOST /api/v1/auth/oauth/{provider}/callbackroutes that reuse the existing state management.
This extends sign-in only. It does not make Plexichat an authorization server.
Security considerations
These practices apply to the implemented inbound flow and to the future authorization-server design.
State token
- Generate state with a cryptographically secure random source (32 bytes or more).
- Store state server-side with a short TTL (10 minutes).
- Verify state on callback and mark it used after a single use.
PKCE
- Use SHA-256 for the code challenge (
S256). - Generate code verifiers with at least 32 bytes of entropy.
- Never include the code verifier in the authorization URL.
Client secrets
- Never expose secrets in client-side code.
- Store secrets in environment variables or your system keyring.
- Rotate secrets periodically.
Redirect URI validation
- Register every valid redirect URI and validate it strictly.
- Use HTTPS for redirect URIs in production.
- Prevent open redirects.
Token storage
- Store session tokens securely. Use
HttpOnlycookies where possible. - Handle expiration and re-authentication.