Skip to content

Latest commit

 

History

History
70 lines (45 loc) · 1.61 KB

readme.md

File metadata and controls

70 lines (45 loc) · 1.61 KB

Google OAuth 2.0 with Express.js

This project shows how to integrate Google OAuth 2.0 with an Express.js application.

Setup

  1. Clone the repository:

    git clone https://github.com/namelesskull/simple-google-oauth.git
    cd simple-google-oauth
  2. Install dependencies:

    npm install
  3. 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"
    
  4. 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.

Usage

  1. Start the server:

    npm start

    or using nodemon

    npm run dev
  2. Authenticate:

    • Visit http://localhost:3000/ and follow the link to sign in with Google.

Troubleshooting

  • redirect_uri_mismatch: Ensure the redirect URI matches in Google Cloud Console and your app.
  • Missing client_id: Check your .env file for correct GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET.

License

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!