Production-ready Google OAuth SSO for Vector internal web applications.
- 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
@vector-institute/aieng-auth-core- Framework-agnostic OAuth client with PKCE@vector-institute/aieng-auth-react- React hooks and components (AuthProvider, useAuth, ProtectedRoute)demo-react- Client-side OAuth demo with React SPAdemo-nextjs- Server-side OAuth demo with Next.js App Router
pnpm add @vector-institute/aieng-auth-reactimport { AuthProvider } from '@vector-institute/aieng-auth-react';
const authConfig = {
clientId: 'YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com',
redirectUri: 'http://localhost:3000/callback',
allowedDomains: ['vectorinstitute.ai'], // Optional: restrict by email domain
};
function App() {
return (
<AuthProvider config={authConfig}>
<YourApp />
</AuthProvider>
);
}import { useAuth } from '@vector-institute/aieng-auth-react';
function MyComponent() {
const { isAuthenticated, user, login, logout } = useAuth();
if (!isAuthenticated) {
return <button onClick={login}>Sign in with Google</button>;
}
return (
<div>
<h1>Welcome, {user.name}!</h1>
<button onClick={logout}>Logout</button>
</div>
);
}┌─────────────────────────────────────────────┐
│ Google Cloud Console │
│ ┌─────────────────────────────────┐ │
│ │ ONE OAuth 2.0 Client │ │
│ │ • Client ID: xxx.apps.google... │ │
│ │ • Redirect URIs: │ │
│ │ - app1.com/callback │ │
│ │ - app2.com/callback │ │
│ │ - app3.com/callback │ │
│ └─────────────────────────────────┘ │
└─────────────────────────────────────────────┘
│
│ Same Client ID
├──────────┬──────────┬──────────
│ │ │
┌──────▼──┐ ┌─────▼────┐ ┌──▼────────┐
│ App 1 │ │ App 2 │ │ App 3 │
│ Admin │ │ Dash │ │ Tools │
│ Portal │ │ board │ │ │
└─────────┘ └──────────┘ └───────────┘
▲ ▲ ▲
└────────────┴────────────┘
Seamless SSO across all apps
All apps share one OAuth client. To add auth to a new app:
- Get the shared client ID from your admin
- Ask admin to add your redirect URI to the OAuth client
- Install and configure with environment variables
- Create OAuth 2.0 credentials in Google Cloud Console
- Set application type to Web application
- Add all app callback URLs to Authorized redirect URIs
- Share the Client ID with developers
# .env
VITE_GOOGLE_CLIENT_ID=123456789-xxx.apps.googleusercontent.com
VITE_REDIRECT_URI=http://localhost:3000/callback
VITE_ALLOWED_DOMAINS=vectorinstitute.aicd apps/demo-react
cp .env.example .env # Add your Google OAuth Client ID
pnpm dev # Runs on http://localhost:3000cd apps/demo-nextjs
cp .env.example .env # Add Google OAuth credentials and session secret
pnpm dev # Runs on http://localhost:3001The Next.js demo uses server-side sessions with HTTP-only cookies for enhanced security, while the React demo uses client-side PKCE flow.
- PKCE (Proof Key for Code Exchange) with SHA-256 challenge
- Memory storage (XSS-immune)
- Domain validation for email restrictions
- Automatic token refresh
pnpm install # Install dependencies
pnpm build # Build all packages
pnpm test # Run testsThis project uses Changesets for version management and publishing, with npm Trusted Publishers for secure authentication.
Configure npm Trusted Publishers to allow GitHub Actions to publish without tokens:
-
Log in to npm: Go to npmjs.com and sign in
-
Navigate to Publishing Access:
- For each package (
@vector-institute/aieng-auth-coreand@vector-institute/aieng-auth-react):- Go to the package page (create if it doesn't exist yet)
- Click "Settings" → "Publishing Access"
- Or go directly to:
https://www.npmjs.com/package/@vector-institute/PACKAGE_NAME/access
- For each package (
-
Add GitHub Actions as Trusted Publisher:
- Click "Add Trusted Publisher"
- Select "GitHub Actions"
- Fill in:
- Repository owner:
VectorInstitute - Repository name:
aieng-auth - Workflow name:
publish.yml - Environment name: (leave empty)
- Repository owner:
- Click "Add"
-
Repeat for all packages: Do steps 2-3 for both
@vector-institute/aieng-auth-coreand@vector-institute/aieng-auth-react
Note: If packages don't exist yet on npm, you can either:
- Create them manually first (recommended)
- Or publish the first version using a temporary automation token, then configure trusted publishing
-
Make your changes and commit them to a branch
-
Create a changeset describing your changes:
pnpm changeset
- Select the packages that changed (core, react, or both)
- Select the version bump type (major, minor, or patch)
- Provide a description of the changes
-
Commit the changeset along with your code changes:
git add .changeset git commit -m "feat: your feature description" -
Create a pull request - the changeset file will be included
-
Merge to main - the publish workflow will:
- Create a "Version Packages" PR that updates versions and changelogs
- When you merge the "Version Packages" PR, packages are automatically published to npm
pnpm build # Build all packages
pnpm changeset version # Update versions and changelogs
pnpm changeset publish # Publish to npm
git push --follow-tags # Push version commits and tags