This is a simple example of how to use Google's OAuth2 authentication and authorization in a Node.js application. This example uses the passport.js
library to access Google APIs.
- Node.js installed on your machine
- A Google account
- Clone this repository to your local machine
- Run
npm install
to install the dependencies - Create a new project in the Google Developer Console
- Enable the Google+ API
- Create OAuth2 credentials
- Add
http://localhost:3000/auth/google/callback
as an authorized redirect URI - Create a
.env
file in the root of the project and add the following environment variables:GOOGLE_CLIENT_ID
- Your Google OAuth2 client IDGOOGLE_CLIENT_SECRET
- Your Google OAuth2 client secretSESSION_SECRET
- A secret key for session management
- Run
npm start
to start the application - Open your browser and navigate to
http://localhost:3000