khadka27 / LoginWithGoogle

MIT License
0 stars 0 forks source link

Login With Google

This project demonstrates how to implement Google OAuth authentication using Passport.js in an Express application.

Table of Contents

Features

Technologies Used

Getting Started

Prerequisites

Make sure you have the following installed on your system:

Setup

  1. Clone the repository:

    git clone https://github.com/khadka27/LoginWithGoogle.git
    cd LoginWithGoogle
  2. Install dependencies:

    npm install
  3. Create a .env file:

    Copy the .env.example file and rename it to .env. Then, fill in your Google Client ID, Client Secret, and Session Secret.

    GOOGLE_CLIENT_ID=your_google_client_id
    GOOGLE_CLIENT_SECRET=your_google_client_secret
    SESSION_SECRET=your_session_secret

Google Client ID and Secret

To obtain your Google Client ID and Client Secret, follow these steps:

  1. Go to the Google Cloud Console:

  2. Create a new project:

    • Click on the project dropdown at the top of the page and select "New Project."
    • Enter a name for your project and click "Create."
  3. Enable the Google People API:

    • In the navigation menu, go to APIs & Services > Library.
    • Search for "Google People API" and click on it.
    • Click "Enable."
  4. Create OAuth 2.0 credentials:

    • Go to APIs & Services > Credentials.
    • Click on "Create Credentials" and select "OAuth client ID."
    • Configure the consent screen (if prompted).
    • Select "Web application" as the application type.
    • Add your authorized redirect URI. This should be:
      http://localhost:3000/auth/google/callback
  5. Copy your credentials:

    • After creating the credentials, you will see your Client ID and Client Secret. Copy these values and paste them into your .env file.

Usage

  1. Start the server:

    npm start
  2. Open your browser:

    • Go to http://localhost:3000/ to see the application.
  3. Login with Google:

    • Click the "Login with Google" button to initiate the authentication process.
  4. Check success or failure:

    • If the login is successful, you will be redirected to the Home page.
    • If the login fails, you will be redirected to the failure page.

Troubleshooting

License

This project is licensed under the MIT License. See the LICENSE file for details.



Feel free to copy and paste this into your `README.md` file!