MEAN STAR is a starter application that helps you to easily start your project development with MEAN Stack technology. This project is mainly focused on the Security, integrated OpenID Connect OAuth 2.0 Authorization Code PKCE Flow and jwks jwt verification. It uses the AppAuth-JS which provides the very generic facility to integrate Authorization Code PKCE Flow with any Single-page Application(SPA) technology and with Any OpenID Connect Provider.
There are so many OpenID Connect Provider. For Example: auth0, okta, keyclock, google, onelogin, gluu, etc...
Currently I am using auth0.com. It is a good OpenID Connect provider. You can create free developer accound and test.
https://mean-star.herokuapp.com.
- Integrated AppAuth-JS at front-end Application.
- OpenID Connect OAuth 2.0 Authorization Code PKCE Flow for Client Front-end Application.
- Protected API using jwks jwt verification
- OpenID Connect OAuth 2.0 integration with any OP Providers.
- User and token mapping and managing user sessions using lru-cache.
- Production and development logger, helps to debug problems in production.
- Dockerfile and docker-compose for easy development and deployment.
- Covered Code Coverage
- [M] Mongo DB >= 4.x
- [E] Expressjs >= 4.x
- [A] Angular >= 8.x.x
- [N] Nodejs >= 10.x.x
- Node JS >= 10.x.x
- Mongo DB >= 4.x
- Angular CLI >= 8.3.x, Install it using
npm install -g @angular/[email protected]
- OpenID Connect Provider and Client ID, Use your OpenID Provider to create new client.
cd client
npm i
cd server
npm i
Install npm i -g nodemon
for developement.
Set your OP(OpenID Connect Provider) Client configuration the environments.ts.
export const environment = {
production: false,
apiURL: 'https://localhost:3000',
// OP Server configuration
clientId: '<your_client_id>',
opServer: '<your_op_server_url>',
opServerUserInfoEndpoint: '/userinfo',
opServerExtraParamsInAuthRequest: {
audience: '<your_op_server_url>/api/v2/'
},
redirectURI: 'https://localhost:4200/callback',
logoutRedirectURI: 'https://localhost:4200',
scope: 'openid email profile',
};
For auth0.com, you need to set extra params to get Access Token in JWT form. Please check here for solution. Every OpenID Connect provider has it's own configurations style so you may need to find out for JWT Access Token.
We need JWT Access Token so that we can use the JWKS Public key verification as Node JS Server side.
Use environments.prod.ts for production environment setup.
Rename the from .env.sample to .env.
PORT=3000
DB_URL=mongodb:https://localhost:27017/mean
OP_SERVER_URL=<your_op_server_url>
USERINFO_ENDPOINT=<your_op_server_user_endpoint_path>
CORS_ORIGIN=https://localhost:4200
Set PRODUCTION=true
for production.
npm start
npm start
For development,
npm run dev
For development
docker-compose build
docker-compose up
If you want to stop docker then press ctrl + c + c
, docker-compose down
.
There are many ways to deploy the application.
PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
Follow the below steps for production:
-
Clone or move your code to server and install node_modules.
-
Install PM2
npm i -g pm2
-
Make an angular production build.
cd client ng build --prod
-
Move
client/dist/client
folder toserver/
so that node application serve it.cp -R client/dist/client server/
-
Start PM2 service. which runs your application in the background.
export PRODUCTION=true # or you can add this in .env pm2 start index.js
Angular is a front-end client application and deploy the client application on standard HTTP Server has several benefits. Please check here for more details.
Follow Below steps to deploy on Nginx:
- Install NGINX Http Server
- Clone or move your code on server and install node_modules.
- Make an angular production build.
cd client ng build --prod
- Move
/client/dist/client/*
all files into/var/www/html
- Start your node app using PM2. No need to set a production flag.
- Added a Proxy Pass configuration for Node Application so that your front-end app can call it.
Docker makes our task very easy. You need to install docker and docker compose on server.
Follow below steps for deploy using docker
- Install docker and docker compose.
- Configure
.env
andenvironment.prod.ts
. - Build the docker image
docker-compose build
- Run docker
docker-compose up
First create a new App
using Heroku dashboard and then follow the below step to build and deploy image on Heroku
heroku container:login
heroku container:push [image-name] -a [your-app-name]
heroku container:release [image-name] -a [your-app-name]