This guide is specifically designed for AI coding assistants like Cursor, Claude Code, GitHub Copilot, and other LLM-powered tools. Copy or download this guide and provide it to your AI assistant for seamless 3PM Auth SSO integration.
This is 3PM Auth, a custom SSO Identity Provider. It is NOT Better Auth or NextAuth. The JWT secret is never shared with client applications—always verify tokens via the/api/verify-token endpoint.
Short-lived token (60s TTL) returned after login. Exchange it server-side for a JWT.
Server-side only! Never expose in client-side code or mobile apps.
Always verify tokens via /api/verify-token API call.
Use httpOnly, secure (production), sameSite: "lax" for all session cookies.
# 3PM Auth ConfigurationIDP_URL=https://idp.3pm.appCLIENT_ID=3pm_xxxxxxxxxxxxxxxxCLIENT_SECRET=3pm_secret_xxxxxxxxxxxxxxxxxxxxxxxx# Your app's public URLNEXT_PUBLIC_APP_URL=http://localhost:3000
/authorizeInitiate SSO login flow
{IDP_URL}/authorize?clientId={CLIENT_ID}&next={CALLBACK_URL}
/api/exchange-tokenExchange GUID for JWT token (server-side only)
// Request{"guid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","clientId": "3pm_xxxxxxxxxxxxxxxx","clientSecret": "3pm_secret_xxxxxxxxxxxxxxxxxxxxxxxx"}// Response (tenant field only for tenant-based apps){"data": {"jwt": "eyJhbGciOiJIUzI1NiIs...","user": {"id": "507f1f77bcf86cd799439011","email": "user@example.com","firstName": "John","lastName": "Doe"},"tenant": { "id": "...", "name": "...", "slug": "...", "role": "admin" }},"error": null}
/api/verify-tokenVerify JWT token and get user data
// Request{"token": "eyJhbGciOiJIUzI1NiIs...","clientId": "3pm_xxxxxxxxxxxxxxxx","clientSecret": "3pm_secret_xxxxxxxxxxxxxxxxxxxxxxxx"}// Response (tenant field only for tenant-based apps){"data": {"valid": true,"user": { ... },"tenant": { "id": "...", "name": "...", "slug": "...", "role": "admin" },"issuedAt": 1704355200,"expiresAt": 1704441600},"error": null}
// Always use these settings for session cookies{httpOnly: true, // Prevents JavaScript accesssecure: true, // HTTPS only (in production)sameSite: "lax", // CSRF protectionpath: "/", // Available to all routesmaxAge: 60 * 60 * 24 // 24 hours (or match IdP session)}
For complete integration examples, download the full AI Integration Guide which includes step-by-step instructions for:
App Router with Server Components
Backend + React Frontend
Mobile with Deep Links
Download the complete AI Integration Guide (1700+ lines) with full code examples for Next.js, Express.js, React, and Flutter.
Last updated: January 2026