page.tsx90 lines · main
| 1 | import { DocsShell } from '../../../components/shell'; |
| 2 | |
| 3 | export const metadata = { title: 'auth · framework packs' }; |
| 4 | |
| 5 | /** |
| 6 | * SuperTokens-class framework integration pack (first cut). |
| 7 | * Copy-paste patterns for wiring Briven Auth into common stacks. |
| 8 | */ |
| 9 | export default function AuthFrameworksPage() { |
| 10 | return ( |
| 11 | <DocsShell> |
| 12 | <h1 className="font-mono text-2xl tracking-tight">auth framework packs</h1> |
| 13 | <p className="mt-2 font-mono text-sm text-[var(--color-text-muted)]"> |
| 14 | drop-in patterns for Briven Auth (briven-engine). Prefer a{' '} |
| 15 | <strong className="text-[var(--color-text)]">first-party proxy</strong> on your |
| 16 | domain so session cookies stay first-party. |
| 17 | </p> |
| 18 | |
| 19 | <h2 className="mt-10 font-mono text-lg">1. Next.js (App Router)</h2> |
| 20 | <pre className="mt-3 overflow-x-auto rounded-md border border-[var(--color-border-subtle)] bg-[var(--color-surface)] p-4 font-mono text-[11px] text-[var(--color-text-muted)]">{`// apps/web/src/app/api/auth/[...path]/route.ts |
| 21 | export async function POST(req: Request, ctx: { params: { path: string[] } }) { |
| 22 | const path = ctx.params.path.join('/'); |
| 23 | const url = \`\${process.env.BRIVEN_API_ORIGIN}/v1/auth-core/fdi/\${path}\`; |
| 24 | const body = await req.text(); |
| 25 | const res = await fetch(url, { |
| 26 | method: 'POST', |
| 27 | headers: { |
| 28 | 'content-type': req.headers.get('content-type') ?? 'application/json', |
| 29 | cookie: req.headers.get('cookie') ?? '', |
| 30 | }, |
| 31 | body, |
| 32 | }); |
| 33 | // forward Set-Cookie to first-party host |
| 34 | return new Response(await res.text(), { |
| 35 | status: res.status, |
| 36 | headers: res.headers, |
| 37 | }); |
| 38 | }`}</pre> |
| 39 | |
| 40 | <h2 className="mt-10 font-mono text-lg">2. Express / Node</h2> |
| 41 | <pre className="mt-3 overflow-x-auto rounded-md border border-[var(--color-border-subtle)] bg-[var(--color-surface)] p-4 font-mono text-[11px] text-[var(--color-text-muted)]">{`app.use('/api/auth', async (req, res) => { |
| 42 | const target = process.env.BRIVEN_API_ORIGIN + '/v1/auth-core/fdi' + req.url; |
| 43 | const r = await fetch(target, { |
| 44 | method: req.method, |
| 45 | headers: { 'content-type': 'application/json', cookie: req.headers.cookie ?? '' }, |
| 46 | body: ['GET', 'HEAD'].includes(req.method) ? undefined : JSON.stringify(req.body), |
| 47 | }); |
| 48 | res.status(r.status).send(await r.text()); |
| 49 | });`}</pre> |
| 50 | |
| 51 | <h2 className="mt-10 font-mono text-lg">3. OIDC “Sign in with Briven” (any stack)</h2> |
| 52 | <ol className="mt-3 list-decimal space-y-2 pl-5 font-mono text-sm text-[var(--color-text-muted)]"> |
| 53 | <li> |
| 54 | Create a client under dashboard → Auth → <strong className="text-[var(--color-text)]">IdP</strong> |
| 55 | </li> |
| 56 | <li> |
| 57 | Discovery:{' '} |
| 58 | <code className="text-[var(--color-text)]"> |
| 59 | GET https://api.briven.tech/v1/auth-core/oidc/.well-known/openid-configuration |
| 60 | </code> |
| 61 | </li> |
| 62 | <li>Use any OIDC library (Auth.js, passport-openidconnect, appauth) with those endpoints</li> |
| 63 | </ol> |
| 64 | |
| 65 | <h2 className="mt-10 font-mono text-lg">4. M2M / server jobs</h2> |
| 66 | <pre className="mt-3 overflow-x-auto rounded-md border border-[var(--color-border-subtle)] bg-[var(--color-surface)] p-4 font-mono text-[11px] text-[var(--color-text-muted)]">{`const tok = await fetch('https://api.briven.tech/v1/auth-core/oauth/token', { |
| 67 | method: 'POST', |
| 68 | headers: { 'content-type': 'application/json' }, |
| 69 | body: JSON.stringify({ |
| 70 | grant_type: 'client_credentials', |
| 71 | client_id: process.env.M2M_CLIENT_ID, |
| 72 | client_secret: process.env.M2M_CLIENT_SECRET, |
| 73 | }), |
| 74 | }).then((r) => r.json()); |
| 75 | // Authorization: Bearer \${tok.access_token}`}</pre> |
| 76 | |
| 77 | <h2 className="mt-10 font-mono text-lg">5. AI agents</h2> |
| 78 | <p className="mt-2 font-mono text-sm text-[var(--color-text-muted)]"> |
| 79 | Mint under Auth → <strong className="text-[var(--color-text)]">AI</strong>, then{' '} |
| 80 | <code className="text-[var(--color-text)]">GET /v1/auth-core/ai/me</code> with{' '} |
| 81 | <code className="text-[var(--color-text)]">Bearer brai_…</code>. |
| 82 | </p> |
| 83 | |
| 84 | <p className="mt-10 font-mono text-xs text-[var(--color-text-muted)]"> |
| 85 | More: <a className="underline" href="/auth">auth overview</a> ·{' '} |
| 86 | <a className="underline" href="/auth/parity">SuperTokens parity walk</a> |
| 87 | </p> |
| 88 | </DocsShell> |
| 89 | ); |
| 90 | } |