This implementation uses hardcoded demo credentials for development and testing purposes:
const GOOGLE_CLIENT_ID = "AUTHKIT_DEMO_CLIENT_ID";
const GOOGLE_CLIENT_SECRET = "AUTHKIT_DEMO_SECRET";Check Google OAuth configuration and get setup instructions.
Response:
{
"success": true,
"message": "Google OAuth Demo Configuration",
"demo": true,
"configuration": {
"client_id": "AUTHKIT_DEMO_CLIENT_ID",
"client_secret": "***",
"demo_user": "demo@authkit.com",
"warning": "β οΈ THIS IS FOR DEMO ONLY - NEVER USE IN PRODUCTION β οΈ"
}
}Initiate Google OAuth (Demo Mode) - Returns instructions instead of redirecting.
Response:
{
"success": true,
"message": "Demo Google OAuth - Use the login endpoint with email parameter",
"demo": true,
"instructions": {
"demoLogin": "POST /api/auth/google/demo with { \"email\": \"demo@authkit.com\" }",
"testLogin": "POST /api/auth/google/demo with { \"email\": \"test@example.com\" }"
}
}Simulate Google OAuth login with any email address.
Request Body:
{
"email": "demo@authkit.com"
}Success Response:
{
"success": true,
"message": "Account created and logged in via Google",
"data": {
"user": {
"id": 1,
"email": "demo@authkit.com",
"firstName": "Demo",
"lastName": "User",
"isVerified": true
},
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": 900,
"provider": "google",
"isNewUser": true
}
}Error Response (OAuth Failure):
{
"success": false,
"error": "Demo mode only. No real keys needed!",
"message": "This is a demo implementation. In production, configure real Google OAuth credentials.",
"code": "DEMO_OAUTH_ERROR"
}Google OAuth callback (Demo Mode) - Returns demo message.
Response:
{
"success": false,
"error": "Demo mode only. No real keys needed!",
"message": "This is a demo callback. Use POST /api/auth/google/demo instead.",
"demo": true
}- Auto-create demo user if email matches
demo@authkit.com - Uses predefined demo user data
- Sets demo password:
demo123 - Logs success:
[DEMO] Auto-creating demo user for demo@authkit.com
- Check if email exists β link to existing account if possible
- Else create new account with Google user data
- Generate random password for OAuth users
- Log:
[OAUTH] Processing Google OAuth for email: user@example.com
- If OAuth fails: Return 500 with message
"Demo mode only. No real keys needed!" - Invalid email: Return 400 with validation error
- Missing email: Return 400 with
"Email is required for demo Google OAuth"
curl -X POST http://localhost:3000/api/auth/google/demo \
-H "Content-Type: application/json" \
-d '{"email": "demo@authkit.com"}'curl -X POST http://localhost:3000/api/auth/google/demo \
-H "Content-Type: application/json" \
-d '{"email": "test@example.com"}'curl http://localhost:3000/api/auth/google/statusTo use real Google OAuth in production:
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials
- Set authorized redirect URIs:
https://yourdomain.com/api/auth/google/callback
- Get your
CLIENT_IDandCLIENT_SECRET
// Replace hardcoded values with environment variables
const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID;
const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET;GOOGLE_CLIENT_ID=your-real-client-id
GOOGLE_CLIENT_SECRET=your-real-client-secret
GOOGLE_REDIRECT_URI=https://yourdomain.com/api/auth/google/callback- Replace demo endpoints with real Google OAuth redirects
- Handle actual OAuth callback with authorization code
- Exchange code for access token
- Fetch user profile from Google API
- Remove demo-specific logic
- Refresh tokens stored in secure httpOnly cookies
- Prevents XSS attacks on OAuth tokens
- Same security as regular authentication
- JWT access tokens with 15-minute expiration
- Refresh token rotation on each use
- Database tracking of all refresh tokens
- Clear warnings about demo credentials
- Fails safely with descriptive error messages
- No real Google API calls made
The implementation includes the required comment:
// This demo uses pre-registered Google credentials. Skip OAuth setup.And comprehensive warnings:
// β οΈ WARNING: THIS IS FOR DEMO ONLY - NEVER USE IN PRODUCTION β οΈ
// These are hardcoded demo credentials for development/testing
// Replace with real Google OAuth credentials in productionπ This is a complete demo implementation that simulates Google OAuth without requiring real Google credentials!