oauth() plugin adds social sign-in to KavachOS using OAuth 2.0 authorization code flow with PKCE. It handles token exchange, account linking, and session creation automatically.
Built-in providers
GitHub
Apple
Discord
Slack
Microsoft
GitLab
Generic setup
lib/kavach.ts
The sign-in flow
- Your frontend redirects to
/auth/oauth/{providerId}/authorize. KavachOS generates a state parameter and PKCE challenge, then redirects to the provider. - The provider redirects back with an authorization code.
- KavachOS exchanges the code for tokens, fetches the user profile, and creates or updates the user record.
- A session cookie is set and the user lands on your redirect destination.
kavach_users.
Account linking
When a sign-in email matches an existing user, KavachOS links the OAuth identity to that account automatically. A single user can connect multiple providers.Custom providers
Any OAuth 2.0 provider works by supplying the authorization and token endpoints:getUserProfile maps the raw provider response to { id, email?, name?, image? }. The id is the provider-side user ID, stored for deduplication.