View as Json

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


Installation Guide

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:

.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

google
github
facebook
google-github
github-facebook
google-facebook
google-facebook-github

File & Folder Structure

Loading files...

Installation

npx servercn-cli add oauth