OAuth with Google and GitHub
This guide will walk you through the process of setting up OAuth authentication for your app using Google and GitHub. You'll need to create OAuth applications on both platforms and retrieve the necessary credentials.
Google OAuth Setup
Create a Google Cloud Project
Go to the Google Cloud Console
Create a new project or select an existing one
Enable the Google+ API
In the sidebar, navigate to "APIs & Services" > "Library"
Search for "Google+ API" and enable it
Create OAuth 2.0 Credentials
Go to "APIs & Services" > "Credentials"
Click "Create Credentials" and select "OAuth client ID"
Choose "Web application" as the application type
Set the authorized JavaScript origins to your app's URL (e.g.,
http://localhost:3000
for local development)Set the authorized redirect URI (e.g.,
http://localhost:3000/api/auth/callback/google
)
Retrieve Google Credentials
After creating the OAuth client, you'll see the client ID and client secret
Save these as
GOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
respectively
GitHub OAuth Setup
Create a GitHub OAuth App
Go to your GitHub account settings
Navigate to "Developer settings" > "OAuth Apps"
Click "New OAuth App"
Register the OAuth App
Enter your app name
Set the homepage URL to your app's main URL
Set the Authorization callback URL (e.g.,
http://localhost:3000/api/auth/callback/github
)
Retrieve GitHub Credentials
After registering, you'll see the client ID
Generate a new client secret
Save these as
GITHUB_CLIENT_ID
andGITHUB_CLIENT_SECRET
respectively
Configuring Your App
Set Environment Variables
In your project's
.env
file, add the following lines:Replace the placeholders with your actual credentials
Last updated