jwt-passport-acl
Stateless Authentication and Authorization Express, Mongoose, Passport, JWT, node-acl written in ES6
Requirements
- Node.js >= 8.x
- MongoDB
Configuration
server/config/config.js
global configuration Database
To establish a connection to the database, you may configure the database connection parameters in global configuration default is mongodb://localhost:27017/jwtpassauth.
JWT Secret
The JWT secret key is set in the global configuration file. Edit them to suit your needs. The JWT contains encoded information about the user and a signature that, when decoded, is validated to ensure that the token has not been tampered with.
API
/users/signup
Signup: POST /users/signup
Host: localhost:3001
Content-Type: application/json
{
"email": "[email protected]",
"password": "password"
}
/users/signin
Signin: POST /users/signin
Host: localhost:3001
Content-Type: application/json
{
"email": "[email protected]",
"password": "password"
}
Returned JSON:
{
"success": "Welcome JWT auth Passed",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJAci5kZSIsImlhdCI6MTUzNTQ1MTg5NSwiZXhwIjozMDcwOTA3MzkwfQ.NttgaHSkIonyyn4_Ds9bl50ltF4g93CSWLLOFRJelYk"
}
server/config/authentication.js
Authentication Authentication is based on json web tokens and passwort-jwt. After a successful login the generated token is sent to the requester. To access the protected routes, the requester must sent the token in the header request.
/protected
JWT Protected: GET /protected
Host: localhost:3001
Authorization: Bearer Token
Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJAci5kZSIsImlhdCI6MTUzNTQ1MTg5NSwiZXhwIjozMDcwOTA3MzkwfQ.NttgaHSkIonyyn4_Ds9bl50ltF4g93CSWLLOFRJelYk
Scripts
eslint extends eslint-config-airbnb-base
$ yarn run linter
contains all of eslint-config-airbnb-base default ESLint rules, including ECMAScript 6+.
It requires eslint and eslint-plugin-import
Development start nodemon
$ yarn run serve
References
Blogs and repros about this subject that I enjoy reading.
Credits to: