kavachOS
AuthenticationOAuth providers

Discord

Sign in with Discord using OAuth 2.0.

Get credentials

Create an application

Go to the Discord Developer Portal and click New Application. Give it a name.

Add a redirect URI

Navigate to OAuth2 > General. Under Redirects, add:

https://auth.example.com/auth/oauth/discord/callback

Copy credentials

From OAuth2 > General, copy the Client ID and Client Secret.

Configuration

lib/kavach.ts
import { createKavach } from '@kavachos/core';
import { oauth } from '@kavachos/core/plugins/oauth';

const kavach = await createKavach({
  database: { provider: 'postgres', url: process.env.DATABASE_URL! },
  secret: process.env.KAVACH_SECRET!,
  baseUrl: 'https://auth.example.com',
  plugins: [
    oauth({
      providers: [
        {
          id: 'discord',
          clientId: process.env.DISCORD_CLIENT_ID!,
          clientSecret: process.env.DISCORD_CLIENT_SECRET!,
        },
      ],
    }),
  ],
});
DISCORD_CLIENT_ID=1234567890123456789
DISCORD_CLIENT_SECRET=...

Scopes

Default scopes: identify email

ScopeWhat it unlocks
identifyRead username, discriminator, avatar
emailRead the user's email address
guildsRead the servers the user belongs to
guilds.members.readRead guild membership details

User data returned

FieldSourceNotes
idid fieldStable Discord snowflake ID
emailemail fieldVerified email
nameusername fieldCurrent username (not discriminator)
imageavatar hashConstructed CDN URL

Discord email addresses are verified before the account can use OAuth. You will always receive a verified email when the email scope is requested.

On this page