Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express token based authentication

Example of token based authentication with Node.js, Express.js, MongoDB and Mongoose.

RESTful API endpoints

POST /api/users

Create a new user.

  • Method: POST
  • URL: /api/users
  • Body:
{
  "username": "art",
  "password": "secret"
}

POST /api/users/authenticate

Authenticate user.

  • Method: POST
  • URL: /api/users/authenticate
  • Body:
{
  "username": "art",
  "password": "secret"
}

GET /api/items?token=<token>

Get items as an authenticated user.

  • Method: GET
  • URL: /api/items?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InRlbWEiLCJpYXQiOjE0NTEzMTMxOTgsImV4cCI6MTQ1MTMxNjc5OH0.TOi73nhmqGYU_Ajo-ufKcPk5TMmycyNSW3jDghPAHLc

Example of a token string: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InRlbWEiLCJpYXQiOjE0NTEzMTMxOTgsImV4cCI6MTQ1MTMxNjc5OH0.TOi73nhmqGYU_Ajo-ufKcPk5TMmycyNSW3jDghPAHLc

Install

npm install

Run

npm start

References

About

Example of token based authentication with Node.js, Express.js, MongoDB and Mongoose.

Resources

Stars

13 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages