OAuth with Google and GitHub
Last updated
Last updated
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.
Create a Google Cloud Project
Go to the
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
and GOOGLE_CLIENT_SECRET
respectively
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
and GITHUB_CLIENT_SECRET
respectively
Set Environment Variables
In your project's .env
file, add the following lines:
Copy
Replace the placeholders with your actual credentials