Install SDK
cd test1
npm install auth-platform-sdk
Production docs for Auth Platform and auth-platform-sdk v3.2.0. OAuth 2.0 + PKCE, HttpOnly token handling, session revocation streams, and multi-tenant admin controls.
Get Running
cd test1
npm install auth-platform-sdk
# .env.local
NEXT_PUBLIC_AUTH_SERVER=__AUTH_SERVER__
NEXT_PUBLIC_CLIENT_ID=your-client-id
NEXT_PUBLIC_REDIRECT_URI=http://localhost:3000/callback
NEXT_PUBLIC_AUTH_PROXY_PATH=/api/auth
# server-only
AUTH_CLIENT_SECRET=your-client-secret
AUTH_CLIENT_TYPE=confidential
Create exactly app/api/auth/[...path]/route.ts. Do not use app/api/route.ts for this.
import { createAuthProxy } from 'auth-platform-sdk/server';
import type { NextRequest } from 'next/server';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
const proxy = createAuthProxy();
type Ctx = { params: Promise<{ path?: string[] }> };
async function handler(req: NextRequest, ctx: Ctx): Promise<Response> {
return proxy(req, ctx);
}
export const GET = handler;
export const POST = handler;
Keep the provider inside the <body> element.
// app/layout.tsx
import { AuthProvider } from 'auth-platform-sdk/client';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
<AuthProvider>{children}</AuthProvider>
</body>
</html>
);
}
'use client';
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useAuth } from 'auth-platform-sdk/client';
export default function CallbackPage() {
const router = useRouter();
const { authClient } = useAuth();
useEffect(() => {
(async () => {
await authClient?.handleCallback();
router.replace('/');
})();
}, [authClient, router]);
return <p>Signing you in...</p>;
}
In app/page.tsx:
'use client'.useAuth().onClick={() => login()}.user?.email for signed-in state.npm run dev
Flow to verify:
/callback/ as authenticated userSDK Surface
auth-platform-sdk/clientBrowser + React integration for OAuth flow and authenticated session state.
AuthProvider, useAuth(), AuthClientlogin({ prompt, loginHint }) to control OAuth prompt behavioronAuthChange((isAuth, reason) => ...) for revocation/expiry handlingrestoreSession(), refreshAccessToken(), startAutoRefresh()auth-platform-sdk/serverBFF proxy that keeps secrets/tokens out of browser JavaScript.
createAuthProxy({
authServerUrl: process.env.AUTH_SERVER_URL,
clientSecret: process.env.AUTH_CLIENT_SECRET,
clientType: 'confidential' // or 'public'
});
Use `public` only when your OAuth client is intentionally configured as public (PKCE-only).
Proxy Contract
| Method | Path | Purpose |
|---|---|---|
| POST | /oauth/token | Code exchange, server injects `client_secret` for confidential clients |
| GET | /oauth/logout | Ends upstream auth session + local cookie cleanup |
| POST | /token/refresh | Refresh from HttpOnly cookie |
| POST | /token/verify | Validates access token, returns payload for UI session state |
| POST | /token/revoke | Revokes session and clears local cookies |
| POST | /token/session-check | Lightweight session status check |
| GET | /token/session-stream | SSE stream for force-logout revocation events |
Security Model
Browser (PKCE + state) -> /api/auth/* proxy (secret + HttpOnly cookies) -> Auth Platform
Auth Platform -> proxy verifies/refreshes session -> browser receives auth status only
Operations
OAuth SSO toggle per app, OTP flows, passkeys, admin MFA, and redirect URI policy.
Real-time force logout, refresh token rotation, and active session visibility.
Login history, OAuth consent activity, and admin activity events for security reviews.