Skip to content

cloudentity/ce-samples-oauth2-openid-connect-nodejs-express

Repository files navigation

About

Quickly add OAuth2/OpenId Connect to an Express.js app. In this sample, we will showcase how to easily fetch OAuth2 based accessToken, refreshToken, openid connect idtoken, token claims and user info within the express app.

Run the application

Minimum requirements:

  • NodeJS 20.x+
  • NPM 10.x+

Cloudentity SaaS Tenant

Clone the repo

Clone this github repo

Install dependencies:

# Make sure you are in the correct app directory
cd ce-samples-oauth2-openid-connect-nodejs-express

npm install

Set environment values

Open the .env file and configure these values after registering an OAuth Client application within the Cloudentity SaaS tenant

Alt text

  • Set redirect URL to http://localhost:3002

Alt text

  • Subscribe to scopes to include email, openid, profile , offline

Alt text

  • Make sure PKCE is not enabled for all client applications

Alt text

  • Copy the below values from above created client application to .env file
    • CLIENT ID
    • CLIENT SECRET
    • ISSUER URL

To start the dev server:

node server.js

Verify application

  • Launch http://localhost:3002

  • User will be redirected to Cloudentity login page

Alt text

  • Authenticate the user

  • You will see following tokens, claims and userInfo in the page

Alt text

More Information

Developers can use Cloudentity platform for free to explore one of the most complete OAuth authorization server with advanced OAuth profile and a Financial-API Grade provider. See pricing for different tiers

Use Cloudentity developer portal to explore more dev tutorials, integration articles and OAuth patterns

Contact

For any issues with this repo, please mail issues to support@cloudentity.com