|
| 1 | +## About |
| 2 | + |
| 3 | +Quickly add OAuth2/OpenId Connect to an [Express.js](https://expressjs.com/) app. In this sample, we will showcase how to easily fetch OAuth2 based [accessToken](https://cloudentity.com/developers/basics/tokens/access-token/), [refreshToken](https://cloudentity.com/developers/basics/tokens/refresh-token/), openid connect [idtoken](https://cloudentity.com/developers/basics/tokens/id-token/), token claims and user info within the express app. |
| 4 | + |
| 5 | +## Run the application |
| 6 | + |
| 7 | +**Minimum requirements:** |
| 8 | + |
| 9 | +- NodeJS 20.x+ |
| 10 | +- NPM 10.x+ |
| 11 | + |
| 12 | +**Cloudentity SaaS Tenant** |
| 13 | + |
| 14 | +- Register for a [free Cloudentity SaaS tenant](https://authz.cloudentity.io/register) |
| 15 | + |
| 16 | +**Clone the repo** |
| 17 | + |
| 18 | +Clone this github repo |
| 19 | + |
| 20 | +**Install dependencies:** |
| 21 | + |
| 22 | +```bash |
| 23 | +# Make sure you are in the correct app directory |
| 24 | +cd ce-samples-oauth2-openid-connect-nodejs-express |
| 25 | + |
| 26 | +npm install |
| 27 | +``` |
| 28 | + |
| 29 | +**Set environment values** |
| 30 | + |
| 31 | +Open the `.env` file and configure these values after registering an OAuth Client application within the Cloudentity SaaS tenant |
| 32 | + |
| 33 | +* Create a new workspace |
| 34 | +* [Attach an identity pool with users](https://cloudentity.com/developers/howtos/identity/store-users/) or an external identity provider |
| 35 | +* Create an OAuth client application |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +* Set redirect URL to `http://localhost:3002` |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +* Subscribe to scopes to include `email`, `openid`, `profile` , `offline` |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +* Make sure PKCE is not enabled for all client applications |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +* Copy the below values from above created client application to `.env` file |
| 53 | + * `CLIENT ID` |
| 54 | + * `CLIENT SECRET` |
| 55 | + * `ISSUER URL` |
| 56 | + |
| 57 | + |
| 58 | +**To start the dev server:** |
| 59 | + |
| 60 | +```bash |
| 61 | +node server.js |
| 62 | +``` |
| 63 | + |
| 64 | +**Verify application** |
| 65 | + |
| 66 | +* Launch `http://localhost:3002` |
| 67 | + |
| 68 | +* User will be redirected to Cloudentity login page |
| 69 | + |
| 70 | + |
| 71 | +* Authenticate the user |
| 72 | + |
| 73 | +* You will see following tokens, claims and userInfo in the page |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +## More Information |
| 78 | + |
| 79 | +Developers can use [Cloudentity platform](https://cloudentity.com/) 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](https://cloudentity.com/pricing/) |
| 80 | + |
| 81 | +Use [Cloudentity developer portal](https://cloudentity.com/developers/) to explore more dev tutorials, integration articles and OAuth patterns |
| 82 | + |
| 83 | +## Contact |
| 84 | + |
| 85 | +For any issues with this repo, please mail issues to [[email protected]](mailto:[email protected]) |
0 commit comments