This guide explains how to configure OAuth providers (Google and GitHub) for social login functionality in the Sealed Auction Platform.
The platform now supports social authentication using:
- Google OAuth 2.0 - Users can sign in with their Google account
- GitHub OAuth - Users can sign in with their GitHub account
- Node.js and npm installed
- OAuth applications created on Google and GitHub
- Environment variables configured
- Configure:
- Application type: Web application
- Name: Sealed Auction Platform
- Authorized JavaScript origins:
http://localhost:3000 - Authorized redirect URIs:
http://localhost:3000/auth/google/callback
- Copy the Client ID and Client Secret
Enable the following APIs in your Google Cloud project:
- Google+ API (if available)
- People API
- Go to GitHub Settings > Developer settings > OAuth Apps
- Click New OAuth App
- Configure:
- Application name: Sealed Auction Platform
- Homepage URL:
http://localhost:3000 - Authorization callback URL:
http://localhost:3000/auth/github/callback
- Click Register application
- Copy the Client ID and Client Secret
-
Copy
.env.exampleto.env:cp .env.example .env
-
Update
.envwith your OAuth credentials:# OAuth Configuration GOOGLE_CLIENT_ID=your_google_client_id_here GOOGLE_CLIENT_SECRET=your_google_client_secret_here GITHUB_CLIENT_ID=your_github_client_id_here GITHUB_CLIENT_SECRET=your_github_client_secret_here # JWT Configuration JWT_SECRET=your_jwt_secret_here SESSION_SECRET=your_session_secret_here
npm installnpm start- User clicks social login button → Redirected to OAuth provider
- User authenticates with provider → Provider redirects back with authorization code
- Server exchanges code for tokens → Retrieves user profile
- Server creates/updates user account → Generates JWT token
- User redirected to app with token → Client stores token and updates UI
- JWT tokens for secure authentication
- Session management with express-session
- Token blacklisting for secure logout
- Environment variables for sensitive data
- HTTPS redirect in production
When users authenticate via OAuth:
- A new user account is automatically created if it doesn't exist
- User profile data (name, email) is retrieved from the provider
- The user can immediately start using the platform
- Start the application:
npm start - Open
http://localhost:3000in your browser - Click the login button to open the auth modal
- You should see Google and/or GitHub login buttons (if configured)
- Click a social login button to test the OAuth flow
-
Redirect URI mismatch
- Ensure redirect URIs in OAuth console match exactly
- Check for trailing slashes and protocol (http vs https)
-
Environment variables not loading
- Verify
.envfile exists in project root - Ensure no spaces around equals signs
- Restart server after changing environment variables
- Verify
-
CORS issues
- Check that authorized JavaScript origins are set correctly
- Ensure the application is running on the correct port
-
Social buttons not showing
- Check browser console for errors
- Verify
/api/auth/statusendpoint returns correct configuration - Ensure OAuth credentials are properly set in environment
Enable debug logging by setting:
NODE_ENV=development
DEBUG=passport:*For production deployment:
- Use HTTPS - OAuth providers require HTTPS in production
- Update redirect URIs - Change from localhost to your domain
- Secure environment variables - Use proper secret management
- Update session configuration - Set
secure: truefor cookies - Domain verification - Verify your domain with OAuth providers
- Store OAuth credentials securely using environment variables
- Use strong JWT secrets and rotate them regularly
- Implement proper session timeout and cleanup
- Monitor for suspicious authentication attempts
- Keep OAuth libraries updated to latest versions
GET /auth/google- Initiate Google OAuth flowGET /auth/google/callback- Google OAuth callbackGET /auth/github- Initiate GitHub OAuth flowGET /auth/github/callback- GitHub OAuth callbackGET /api/auth/status- Check OAuth provider availability
POST /api/users/login- Traditional loginPOST /api/users/register- Traditional registrationPOST /api/users/logout- Logout (token blacklisting)GET /api/users/verify- Verify JWT token
For issues with OAuth integration:
- Check the troubleshooting section above
- Review server logs for error messages
- Verify OAuth provider console settings
- Ensure all dependencies are properly installed