zeevest-superapp-sso-sdk
v0.1.0
Published
TypeScript SDK for Single Sign-On (SSO) integration in Next.js applications
Maintainers
Readme
Super App SSO SDK
TypeScript SDK for Single Sign-On (SSO) integration in Next.js applications.
Installation
npm install super-app-sso-sdkQuick Start
1. Middleware Authentication
// middleware.ts
import { authenticate } from 'super-app-sso-sdk';
export async function middleware(request: NextRequest) {
const authRequest = authenticate(request);
try {
const user = await authRequest.auth();
console.log('Authenticated user:', user.username);
} catch (error) {
return new Response('Unauthorized', { status: 401 });
}
}2. API Route with Authentication
// app/api/profile/route.ts
import { authenticate } from 'super-app-sso-sdk';
export async function GET(request: NextRequest) {
const authRequest = authenticate(request);
try {
const user = await authRequest.auth();
return Response.json({ user });
} catch (error) {
return Response.json({ error: 'Unauthorized' }, { status: 401 });
}
}3. Ready-to-use Profile Endpoints
// app/api/profile/route.ts
import { getProfileEndpoint, setProfileEndpoint } from 'super-app-sso-sdk';
export const GET = getProfileEndpoint('https://sso-server.example.com');
export const PUT = setProfileEndpoint('https://sso-server.example.com');4. React Hook for User Data
// components/UserProfile.tsx
import { useUser } from 'super-app-sso-sdk';
export function UserProfile() {
const { user, loading, error, refresh } = useUser();
if (loading) return <div>Loading...</div>;
if (error) return <div>Error: {error}</div>;
if (!user) return <div>Not authenticated</div>;
return (
<div>
<h1>Welcome, {user.firstName}!</h1>
<button onClick={refresh}>Refresh</button>
</div>
);
}Configuration
Set environment variables:
# Header name (default: Bistoun-OAD)
BISTOUN_OAD_HEADER=Bistoun-OAD
# RSA private key path (default: .key)
SSO_KEY_PATH=.keyAPI Reference
Authentication
authenticate(request: NextRequest): AuthenticatedNextRequest
HTTP Client
createApiClient(config: ApiClientConfig): RawService
Profile Endpoints
getProfileEndpoint(ssoServerURL: string): ProfileEndpointHandlersetProfileEndpoint(ssoServerURL: string): ProfileEndpointHandler
React Hooks
useUser(options?: UseUserOptions): UseUserResult
Types
interface UserProfile {
id: string;
username: string;
email?: string;
firstName?: string;
lastName?: string;
roles?: string[];
permissions?: string[];
metadata?: Record<string, unknown>;
}License
MIT
