CRITICAL: This documentation site (docs.cnclab.io) uses client-side authentication to restrict access to lab members only.
Security ImplementationΒΆ
How It WorksΒΆ
Client-side authentication gate (
_static/auth-gate.js) runs on every page loadGoogle OAuth integration uses same system as main site (cnclab.io)
Lab member verification against existing team whitelist API
Secure token storage in browser localStorage with expiration
Authentication FlowΒΆ
1. User visits docs.cnclab.io
2. auth-gate.js loads and checks for stored token
3. If no token: redirect to Google OAuth
4. OAuth callback processes authorization code
5. Main site API exchanges code for access token
6. Email verified against lab member whitelist
7. Token stored locally, user sees documentationDeployment RequirementsΒΆ
Vercel Environment Variables (Main Site: cnclab.io)ΒΆ
These must be configured in the Vercel dashboard for the main site project:
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secretGoogle OAuth ConfigurationΒΆ
In your Google Cloud Console OAuth client, add these authorized redirect URIs:
https://docs.cnclab.io/auth/callbackFile StructureΒΆ
docs-book/
βββ _static/
β βββ auth-gate.js # Client-side authentication script
βββ auth/
β βββ callback.html # OAuth callback handler
βββ _config.yml # Injects auth-gate.js into all pages
βββ vercel.json # Deployment configuration
βββ DEPLOYMENT_SECURITY.md # This guideAPI Endpoints (Main Site)ΒΆ
/api/docs/configΒΆ
Purpose: Provides auth configuration for docs site
Response:
{ success: true, config: { enableAuth: true, googleClientId: "..." } }CORS: Enabled for docs.cnclab.io
/api/auth/exchange-tokenΒΆ
Purpose: Securely exchanges OAuth code for access token
Method: POST
Body:
{ code: "oauth_authorization_code" }Response:
{ success: true, access_token: "...", email: "...", name: "..." }
/api/auth/whitelistΒΆ
Purpose: Returns list of authorized lab member emails
Response:
{ success: true, emails: ["email1@domain.com", ...] }
Testing AuthenticationΒΆ
β With Authentication Enabled (Production)ΒΆ
Visit docs.cnclab.io
Should show Google login page
After login with lab email β documentation visible
Login with non-lab email β access denied
β οΈ TroubleshootingΒΆ
Site shows login but fails after Google auth:
Check Google OAuth redirect URIs include:
https://docs.cnclab.io/auth/callbackVerify
GOOGLE_CLIENT_SECRETis set in main site Vercel env vars
βCould not load auth configβ in browser console:
Check main site
/api/docs/configendpoint is accessibleVerify CORS headers allow docs.cnclab.io
User gets βAccess deniedβ after successful Google auth:
Verify userβs email is in the team Google Sheet
Check
/api/auth/whitelistendpoint returns their email
Security FeaturesΒΆ
β No credentials in static files - all auth handled via API calls
β Token expiration - 5 minute automatic re-verification
β State verification - prevents CSRF attacks in OAuth flow
β Email whitelist - only authorized lab members can access
β Secure token exchange - authorization codes exchanged server-side
β CORS protection - API endpoints only allow docs.cnclab.io origin
Emergency AccessΒΆ
If authentication breaks and you need to disable it temporarily:
Go to main site Vercel dashboard
Remove
GOOGLE_CLIENT_IDenvironment variableRedeploy main site
Docs site will fall back to public access
The auth-gate.js script automatically detects missing configuration and allows public access as fallback.
Last Updated: September 6, 2025
Next Review: After any changes to OAuth setup or team member management