Authentication
Twitter / X
Sign in with Twitter using OAuth 2.0.
Setup
Get credentials
Go to the Twitter Developer Portal and create a project and app. Under User authentication settings, enable OAuth 2.0 and set the redirect URI to:
https://your-app.com/api/kavach/auth/oauth/callback/twitterSet the app type to Web App and enable Read permissions at minimum.
Configure
import { createKavach } from 'kavachos';
import { oauth } from 'kavachos/auth';
import { createTwitterProvider } from 'kavachos/auth';
const kavach = await createKavach({
database: { provider: 'sqlite', url: 'kavach.db' },
plugins: [
oauth({
providers: [
createTwitterProvider({
clientId: process.env.TWITTER_CLIENT_ID!,
clientSecret: process.env.TWITTER_CLIENT_SECRET!,
}),
],
}),
],
});TWITTER_CLIENT_ID=...
TWITTER_CLIENT_SECRET=...Scopes
Default scopes: users.read, tweet.read
| Scope | What it unlocks |
|---|---|
users.read | Read the user's profile |
tweet.read | Read tweets |
offline.access | Refresh token support |
Twitter does not return an email address through the standard OAuth 2.0 flow. KavachOS uses a synthetic non-deliverable address (username@twitter.invalid) as a placeholder. Do not treat it as a real email.
Endpoints
| Method | Path | Description |
|---|---|---|
| GET | /auth/oauth/authorize/twitter | Redirect to Twitter |
| GET | /auth/oauth/callback/twitter | Handle callback |