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.
Minimum requirements:
- NodeJS 20.x+
- NPM 10.x+
Cloudentity SaaS Tenant
- Register for a free 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
- Create a new workspace
- Attach an identity pool with users or an external identity provider
- Create an OAuth client application
- Set redirect URL to
http://localhost:3002
- Subscribe to scopes to include
email
,openid
,profile
,offline
- Make sure PKCE is not enabled for all client applications
- Copy the below values from above created client application to
.env
fileCLIENT 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
-
Authenticate the user
-
You will see following tokens, claims and userInfo in the page
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
For any issues with this repo, please mail issues to support@cloudentity.com