STEP 01
Create an app
Register your name and callback URL in the console.
ChaiAuth is an OpenID Connect provider. Passkeys, two-factor auth, sessions and consent all run on our UI. Your app just speaks standard OIDC.
Three steps from zero to a signed-in user.
STEP 01
Register your name and callback URL in the console.
STEP 02
Send users to /authorize with state and a PKCE challenge.
STEP 03
Swap the code for tokens on your server.
Create credentials in the developer console. Redirect URIs must use HTTPS (http is allowed only for localhost) and are matched exactly.
| Setting | Example |
|---|---|
| Client ID | ca_live_8f2k1m9qz4 |
| App URL | https://yourapp.com |
| Redirect URI | https://yourapp.com/auth/callback |
| Scopes | openid profile email |
ChaiAuth publishes an OpenID discovery document, so Auth.js finds the token, userinfo and JWKS endpoints by itself.
npm install next-authimport NextAuth from "next-auth";
export const authOptions = {
providers: [
{
id: "chaiauth",
name: "ChaiAuth",
type: "oauth",
wellKnown: "https://auth-api.kenilpatel.in/.well-known/openid-configuration",
clientId: process.env.CHAIAUTH_CLIENT_ID,
clientSecret: process.env.CHAIAUTH_CLIENT_SECRET,
authorization: { params: { scope: "openid profile email" } },
idToken: true,
checks: ["pkce", "state"],
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
};
},
},
],
};
export default NextAuth(authOptions);https://auth-api.kenilpatel.in/.well-known/openid-configuration and use the Authorization Code flow with PKCE.https://chaiauth.kenilpatel.in/authorize
?response_type=code
&client_id=YOUR_CLIENT_ID
&redirect_uri=https://yourapp.com/auth/callback
&scope=openid profile email
&state=RANDOM_STATE
&nonce=RANDOM_NONCE
&code_challenge=BASE64URL_SHA256_OF_VERIFIER
&code_challenge_method=S256Do this on your server so the client secret never reaches the browser. Public clients (SPA / mobile) skip client_secret and rely on PKCE.
# Exchange the code for tokens (server side)
curl -X POST https://auth-api.kenilpatel.in/o/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "code=AUTHORIZATION_CODE" \
-d "redirect_uri=https://yourapp.com/auth/callback" \
-d "code_verifier=YOUR_PKCE_VERIFIER"{
"access_token": "eyJhbGciOi...",
"id_token": "eyJhbGciOi...",
"refresh_token": "a1b2c3...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "openid profile email"
}grant_type=refresh_token with your refresh token to get new access tokens.@chaiauth/react runs the whole flow for you: PKCE, state and nonce checks, token refresh and sign-out, with ready-made components.
"use client";
import { ChaiAuthProvider } from "@chaiauth/react";
export function Providers({ children }: { children: React.ReactNode }) {
return (
<ChaiAuthProvider
clientId={process.env.NEXT_PUBLIC_CHAIAUTH_CLIENT_ID!}
redirectUri="https://yourapp.com/auth/callback" // exactly as registered
issuer="https://auth-api.kenilpatel.in"
>
{children}
</ChaiAuthProvider>
);
}import { SignIn, SignedIn, SignedOut, UserButton, useChaiAuth } from "@chaiauth/react";
export function Header() {
return (
<header>
<SignedOut>
<SignIn returnTo="/dashboard" />
</SignedOut>
<SignedIn>
<UserButton accountUrl="https://chaiauth.kenilpatel.in/dashboard" />
</SignedIn>
</header>
);
}
// Calling your own backend with the user's access token
export function useApi() {
const { getAccessToken } = useChaiAuth();
return async (path: string) => {
const token = await getAccessToken(); // refreshed automatically when needed
return fetch(path, { headers: { Authorization: `Bearer ${token}` } });
};
}<ChaiAuthProvider>. The package lives in this repo (packages/react) until it is published to npm.Base URL: https://auth-api.kenilpatel.in
/.well-known/openid-configurationOpenID provider metadata/.well-known/jwks.jsonPublic keys to verify ID tokens (RS256)/o/authorizeValidate an authorization request/o/tokenExchange a code or refresh token for tokens/o/userinfoRead approved profile claims (Bearer token)/o/revokeRevoke a token/v1/usersList users who granted your app access (API key)/v1/users/:userIdRead one user's approved claims (API key)Request only what you need. Unsupported scopes are ignored; a request with no supported scope is rejected.
openidRequired for OIDC. Returns an ID token with the sub claim.
profileThe user's name.
emailThe user's email and email_verified.
Create an API key in the developer console (open your app, then API keys) to call ChaiAuth from your own backend, without a user present.
# List the users who granted your app access
curl "https://auth-api.kenilpatel.in/v1/users?limit=20" \
-H "Authorization: Bearer ca_live_YOUR_API_KEY"
# One user
curl "https://auth-api.kenilpatel.in/v1/users/USER_ID" \
-H "Authorization: Bearer ca_live_YOUR_API_KEY"{
"success": true,
"data": {
"sub": "8f14e45f-ceea-4f67-9c1e-2b9d3a6b1c7e",
"name": "Asha Patel",
"email": "asha@example.com",
"email_verified": true,
"scope": "openid profile email",
"granted_at": "2026-11-09T10:15:00.000Z"
}
}