Skip to content

fedosejev/express-api-token-authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

Watchers

Forks

Releases

No releases published

Packages

No packages published