diff --git a/README.md b/README.md index ef2049e..da7c53b 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,21 @@ # @aieng-auth -> Production-ready Google OAuth SSO for all your web applications +Production-ready Google OAuth SSO for Vector internal web applications. -Seamless single sign-on across multiple apps using **one shared Google OAuth client**. Perfect for organizations that want to add authentication to internal tools with minimal configuration. +## Key Features -## đ¯ Key Features +- Share one Google OAuth client across multiple apps for seamless SSO +- Client-side OAuth with PKCE security (no backend required) +- Domain restriction by email (e.g., @vectorinstitute.ai) +- React hooks and components with full TypeScript support -- **Single OAuth Client, Multiple Apps** - All your apps share one Google OAuth client for seamless SSO -- **3-Step Integration** - Install, wrap, configure. That's it. -- **Domain Restriction** - Restrict access to specific email domains (e.g., @vectorinstitute.ai) -- **Zero Backend Required** - Pure client-side OAuth with PKCE security -- **Framework Support** - React hooks + components (Next.js coming soon) -- **TypeScript First** - Fully typed for excellent DX +## Packages -## đĻ Packages +- `@aieng-auth/core` - Framework-agnostic OAuth client with PKCE +- `@aieng-auth/react` - React hooks and components (AuthProvider, useAuth, ProtectedRoute) +- `demo-react` - Demo application -- **`@aieng-auth/core`** â - Framework-agnostic OAuth client with PKCE -- **`@aieng-auth/react`** â - React hooks and components (AuthProvider, useAuth, ProtectedRoute) -- **`demo-react`** â - Live demo application - -## đ Quick Start +## Quick Start ### 1. Install @@ -68,7 +64,7 @@ function MyComponent() { } ``` -## đī¸ Architecture: Single OAuth Client Model +## Architecture ``` âââââââââââââââââââââââââââââââââââââââââââââââ @@ -96,28 +92,22 @@ function MyComponent() { Seamless SSO across all apps ``` -**For Developers**: Adding auth to a new app is simple: +All apps share one OAuth client. To add auth to a new app: 1. Get the shared client ID from your admin -2. Ask admin to register your redirect URI -3. Install package and configure (2 env vars) -4. Done! - -## đ§ Setup Google OAuth +2. Ask admin to add your redirect URI to the OAuth client +3. Install and configure with environment variables -### One-Time Admin Setup +## Setup Google OAuth -1. Go to [Google Cloud Console](https://console.cloud.google.com/) -2. Create a project or select existing -3. Enable Google+ API -4. Create OAuth 2.0 credentials: - - Application type: **Web application** - - Authorized redirect URIs: Add all your app callback URLs -5. Copy the Client ID +### Admin Setup (One-Time) -### Per-App Setup +1. Create OAuth 2.0 credentials in [Google Cloud Console](https://console.cloud.google.com/) +2. Set application type to Web application +3. Add all app callback URLs to Authorized redirect URIs +4. Share the Client ID with developers -Each developer just needs: +### Developer Setup ```bash # .env @@ -126,41 +116,27 @@ VITE_REDIRECT_URI=http://localhost:3000/callback VITE_ALLOWED_DOMAINS=vectorinstitute.ai ``` -## đ Demo +## Demo -See the live demo in `apps/demo-react`: +Run the demo app: ```bash cd apps/demo-react -cp .env.example .env -# Add your Google OAuth Client ID +cp .env.example .env # Add your Google OAuth Client ID pnpm dev ``` -## đ Security +## Security -- **PKCE (Proof Key for Code Exchange)** - Prevents authorization code interception -- **SHA-256 Challenge** - Cryptographically secure -- **Memory Storage (default)** - XSS-immune token storage -- **Domain Validation** - Restrict access by email domain -- **Automatic Token Refresh** - Seamless session management +- PKCE (Proof Key for Code Exchange) with SHA-256 challenge +- Memory storage (XSS-immune) +- Domain validation for email restrictions +- Automatic token refresh -## đ ī¸ Development +## Development ```bash -# Install dependencies -pnpm install - -# Build all packages -pnpm build - -# Run tests -pnpm test - -# Run demo -cd apps/demo-react && pnpm dev +pnpm install # Install dependencies +pnpm build # Build all packages +pnpm test # Run tests ``` - -## đ License - -MIT diff --git a/apps/demo-nextjs/src/app/dashboard/page.tsx b/apps/demo-nextjs/src/app/dashboard/page.tsx index 68ce45b..946a0b6 100644 --- a/apps/demo-nextjs/src/app/dashboard/page.tsx +++ b/apps/demo-nextjs/src/app/dashboard/page.tsx @@ -15,8 +15,8 @@ export default async function DashboardPage() { return (
Protected page - server-side authentication
+Protected page with server-side authentication
- This page is protected by server-side middleware. You can only see it because you're - authenticated. + This page is protected by server-side middleware.
-Server-side sessions with App Router
+Server-side authentication with App Router
- This demo shows server-side OAuth with Next.js App Router. Unlike the React SPA, - tokens are stored securely in HTTP-only cookies. + Server-side OAuth with HTTP-only cookies for secure token storage.
Tokens never touch the browser. Stored in HTTP-only cookies on the server.
+Tokens stored in HTTP-only cookies, never exposed to browser.
- Authentication works with Server Components. No client-side JavaScript required. -
+Authentication integrated with Next.js Server Components.
Built for production with session management and automatic token refresh.
+Session management with automatic token refresh.
- You're signed in with server-side session management! -
+Server-side session active.
/api/auth/callback
- Protected page - only accessible when authenticated
+Protected page
- This is a protected route. You can only see this page because you're authenticated. -
+useAuth() hook to access user and auth state
- useToken() hook to get access token for API calls
- <ProtectedRoute> component
- Test the CyberArk Auth core package
+Test the aieng-auth core package
{JSON.stringify(
@@ -153,9 +153,9 @@ export default function DemoPage() {
- {storageType === 'memory' && 'đ Most secure - tokens lost on refresh'} - {storageType === 'session' && 'â ī¸ Persists during session - XSS vulnerable'} - {storageType === 'local' && 'â ī¸ Persists across sessions - least secure'} + {storageType === 'memory' && 'Most secure - tokens lost on refresh'} + {storageType === 'session' && 'Persists during session - XSS vulnerable'} + {storageType === 'local' && 'Persists across sessions - least secure'}
{JSON.stringify(
@@ -195,8 +195,7 @@ export default function DemoPage() {
Token Validation:
- Expired:{' '}
- {isTokenExpired(tokens.accessToken) ? 'â Yes' : 'â
No'}
+ Expired: {isTokenExpired(tokens.accessToken) ? 'Yes' : 'No'}
Decoded Claims:
@@ -211,14 +210,14 @@ export default function DemoPage() {
{!tokens && (
- âšī¸ No tokens stored
+ No tokens stored
)}
{/* Info Section */}
- đ Next Steps
+ Next Steps
-
For Real OAuth: Configure .env with your Google OAuth credentials
diff --git a/apps/demo-react/src/pages/home-page.tsx b/apps/demo-react/src/pages/home-page.tsx
index 9f3cd40..f537fbb 100644
--- a/apps/demo-react/src/pages/home-page.tsx
+++ b/apps/demo-react/src/pages/home-page.tsx
@@ -18,8 +18,8 @@ export default function HomePage() {
return (
-
đ Google OAuth SSO Demo
- Seamless authentication across all your apps
+ Google OAuth SSO Demo
+ Production-ready authentication for internal applications
{error && (
@@ -32,14 +32,13 @@ export default function HomePage() {
{!isAuthenticated ? (
<>
- Welcome!
+ Welcome
- This demo shows how simple it is to add Google OAuth SSO to your app using{' '}
- @aieng-auth/react
+ Add Google OAuth SSO using @aieng-auth/react
- ⨠Integration is 3 steps:
+ Quick Start:
-
Install:
pnpm add @aieng-auth/react
@@ -47,50 +46,37 @@ export default function HomePage() {
-
Wrap app with
<AuthProvider>
- -
- Set env vars:
CLIENT_ID and REDIRECT_URI
-
+ - Configure CLIENT_ID and REDIRECT_URI
- đ¯ Single OAuth Client
-
- All your apps share one Google OAuth client. Add new apps by just registering their
- redirect URIs.
-
+ Single OAuth Client
+ Share one Google OAuth client across multiple apps for seamless SSO.
- đ Domain Restriction
-
- Restrict access to @vectorinstitute.ai emails. Only authorized users can sign in.
-
+ Domain Restriction
+ Restrict access by email domain for authorized users only.
- ⥠Zero Backend
-
- Pure client-side with PKCE security. No server needed for OAuth flow. Deploy
- anywhere.
-
+ Client-side OAuth
+ PKCE security with no backend required.
>
) : (
<>
- â
Authenticated
-
- You're signed in! This authentication works across all apps using the same OAuth
- client.
-
+ Authenticated
+ Signed in successfully.
{user?.picture && (
@@ -120,7 +106,7 @@ export default function HomePage() {
-
+
- đ¨ How This Works
+ Authentication Flow
- - User clicks "Sign in with Google"
- - Redirects to Google OAuth (with PKCE challenge)
- - User authorizes and redirects back to /callback
- - Exchanges code for tokens (with PKCE verifier)
- - Validates email domain (if configured)
- - Stores tokens and user info in context
- - App can now make authenticated requests
+ - Initiate OAuth with PKCE challenge
+ - Redirect to Google for authorization
+ - Exchange authorization code for tokens
+ - Validate email domain
+ - Store session and user info
>
diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json
index fd10840..362ab16 100644
--- a/packages/eslint-config/package.json
+++ b/packages/eslint-config/package.json
@@ -2,7 +2,7 @@
"name": "@aieng-auth/eslint-config",
"version": "0.1.0",
"private": true,
- "description": "Shared ESLint configuration for AIEng Auth packages",
+ "description": "Shared ESLint configuration for aieng-auth packages",
"main": "index.js",
"files": [
"index.js"