This project shows how to integrate Google OAuth 2.0 with an Express.js application.
-
Clone the repository:
git clone https://github.com/namelesskull/simple-google-oauth.git cd simple-google-oauth
-
Install dependencies:
npm install
-
Create a
.env
file:touch .env
Copy this
.env.example
to.env
and add your Google OAuth credentials:GOOGLE_CLIENT_ID="YOUR_GOOGLE_CLIENT_ID" GOOGLE_CLIENT_SECRET="YOUR_GOOGLE_CLIENT_SECRET" SESSION_SECRET="YOUR_SESSION_SECRET"
-
Configure Google OAuth:
- Go to Google Cloud Console.
- Create a project and set up OAuth 2.0 credentials.
- Add the redirect URI
http://localhost:3000/auth/google/callback
.
-
Start the server:
npm start
or using nodemon
npm run dev
-
Authenticate:
- Visit
http://localhost:3000/
and follow the link to sign in with Google.
- Visit
- redirect_uri_mismatch: Ensure the redirect URI matches in Google Cloud Console and your app.
- Missing client_id: Check your
.env
file for correctGOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
.
MIT License For more details, check the Google OAuth 2.0 documentation.
Don't forget to ⭐️ star this repository and follow my GitHub for more updates!