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.

Official Docs

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

npx servercn-cli add oauth

You will be prompted to select a file upload provider:

? Select OAuth provider:  ยป - Use arrow-keys. Return to submit.
    Google
    GitHub
>   Google + GitHub

The CLI will then automatically configure the component based on your selected provider.

Prerequisites

  1. Go to the Google Cloud Console
  2. Create/Select a project -> Enable Google+ API
  3. Create Credentials -> OAuth Client ID -> Web Application
  4. Authorized Redirect URI: http://localhost:3000/api/auth/google/callback
  5. Copy Client ID and Client Secret
  1. Go to GitHub Settings > Developer settings
  2. New OAuth App
  3. Authorization callback URL: http://localhost:3000/api/auth/github/callback
  4. Copy Client ID and Client Secret

Add to your .env:

GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
GOOGLE_REDIRECT_URI="your-google-redirect-uri"
 
GITHUB_CLIENT_ID="your-github-client-id"
GITHUB_CLIENT_SECRET="your-github-client-secret"
GITHUB_REDIRECT_URI="your-github-redirect-uri"

Related Components

File & Folder Structure

ServerCN

Select a file to view its contents

Installation

npx servercn-cli add oauth