This is a simple example of how to use passport with oauth2. It uses the google strategy to authenticate users.
- Clone the repository
- Run
npm install
- Create a
.env
file in the root directory and add the following variables:
NODE_ENV=development
PORT=3000
APP_SECRET=your_app_secret
# Database
DB_HOST=localhost
DB_PORT=3306
DB_CONNECTION=mysql
DB_USERNAME=your_db_user
DB_PASSWORD=your_db_password
DB_NAME=your_db_name
# Google Oauth2
OAUTH2_AUTHORIZATION_URL=https://accounts.google.com/o/oauth2/v2/auth
OAUTH2_TOKEN_URL=https://oauth2.googleapis.com/token
AUTH_CLIENT_ID=your_client_id
AUTH_CLIENT_SECRET=your_client_secret
AUTH_CALLBACK_URL=http://localhost:3000/auth/google/callback
- Run
npm start
- Open your browser and go to
http://localhost:3000