Add authentication of users with their Google account in Node.js / Auth0

This page explains how to add user authentification with Auth0

Auth0 is a cloud-based platform that provides authentication and authorization services for applications. It allows developers to authenticate users using a variety of methods, including social logins (Google, Twitter, Facebook...), single sign-on, and multi-factor authentication. Auth0 also provides tools for managing user profiles and permissions, as well as API security and access control. It is designed to make it easy for developers to add secure authentication and authorization to their applications, without having to build these capabilities from scratch.

The following has been performed with the following versions:

Install package

Let's start by creating the Node.js project:

npm init -y 

Let's now install the required packages

npm install express dotenv express-openid-connect 

Auth0 account

Create an account on Auth0.

Once your logged, create a new application. Set your application name and select regular Web Application:

Create a new web application on Auth0 web site

Select Node.js app:

Select Node.js app

Then create a new Node.js project (Explore Sample App):

Explore a sample app

The next page is the configuration page. Leave the default parameters and click on Save And Download App. A file name 01-login.zip should be downloaded/

Unzip the file in your project folder.

Node.js version [Optional]

[Optional] Note that I use Volta to run any version of Node.js. In my case, I ran:

volta install node@18.13.0
volta install npm@8.19.2

Pin you Node.js and npm version in the project:

volta pin node@18.13.0
volta pin npm@8.19.2

Start the application

Execute the following commands in the sample's directory:

npm install
npm start

In your favorite browser, go to http://localhost:3000/ :

Home page of the Auth0 aythentification app

Log-in, go to your profile page and check your profil information:

Profile information provided by Google / Auth0

See also


Last update : 01/08/2023