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
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: