GitHub & Google OAuth (Passport)
The GitHub & Google OAuth component provides a secure and standardized way to integrate both GitHub and Google authentication into your ServerCN Express applications using passport, passport-google-oauth20, and passport-github2.
Features
- Unified OAuth 2.0 flow - Handle both Google and GitHub logins in a single integration
- Secure by default - CSRF protection
- Express integration - Ready-to-use route handlers
- Type-safe - Full TypeScript support
Installation Guide
This component requires additional ServerCN components.
๐ You do not need to install any ServerCN components manually. Running this component installer will automatically install all required components. Manual installation is optional and only recommended if you prefer fine-grained components control
1. Install ServerCN components(Optional)
2. Install this component
npx servercn-cli add oauthYou will be prompted to select a file upload provider:
The CLI will then automatically configure the component based on your selected provider.
Prerequisites
Google Cloud Console Setup
- Go to the Google Cloud Console
- Create/Select a project -> Enable Google+ API
- Create Credentials -> OAuth Client ID -> Web Application
- Authorized Redirect URI:
http://localhost:3000/api/auth/google/callback - Copy Client ID and Client Secret
GitHub OAuth Setup
- Go to GitHub Settings > Developer settings
- New OAuth App
- Authorization callback URL:
http://localhost:3000/api/auth/github/callback - Copy Client ID and Client Secret
Environment Variables
Add to your .env: