Skip to content

Sample Application that Uses JSON web tokens for token-based user authentication.

License

Notifications You must be signed in to change notification settings

divyanshu-rawat/Passport-Authenticated-Rest-Api

Repository files navigation

Join the chat Contact me on Codementor Twitter URL DUB

Divyanshu Say Thanks! Build Status NPM

Description

  • Built a rest Api in Node.js by leveraging below-mentioned Node.js modules.
  • Used JSON web tokens for token-based user authentication
  • Used Passport module together with passport-local and passport-local-mongoose for setting up local authentication within server.
  • Used Mongoose population to cross-reference users within a comment.
  • Configured a secure server in Node using the core HTTPS module.
  • Generated the private key and public certificate and configure the HTTPS server.
  • Used an OAuth providers for authenticating users within your server.
  • Set up your server using Passport OAuth modules to enable user authentication using OAuth providers.

How it works !

  • Checks if a verified ordinary user also has admin privileges.
  • Allow an ordinary user to only perform GET operatioins
  • Only allows Admin to perform POST, PUT and DELETE operations
  • Only allows Admin to be able to GET all the registered users' information from the database

Installation Instructions ❕

  • Clone or download the repo. into any fresh temporary folder.

  • Cd into that root folder you just cloned locally.

  • Open terminal in the current folder and to install all dependencies type

   npm install 
  • Now typing
   npm start 
  • will start a server !

DB Used (MongoDB)

  • MLab's MongoDB hosting platform is the fastest growing cloud Database-as-a-Service in the world. Get started with a free database and expert support.

Package Manager Used (NPM)

  • NPM is the default package manager for the JavaScript runtime environment Node.js.

Package.json (dependencies)

  • For dependencies refer Package.json.

For Testing (Postman)

  • Postman extension can be used for testing !
  • Supercharge your API workflow with Postman! Build, test, and document your APIs faster.
  • You can now fire up postman and then perform several operations on the REST API.

Sample Data (db.json)

  • You can use the data for all the dishes,promotions and leadership provided in the db.json file .

Contributing

  1. Create your branch: git checkout -b my-new-feature

  2. Commit your changes: git commit -m 'Add some feature'

  3. Push to the branch: git push origin my-new-feature

  4. Send a Pull Request

  5. Enjoy!

Examples

  • POST Request to URL localhost:3443/users/register (For user registration !)

alt tag

  • POST Request to URL localhost:3443/users/login (For user login !)

alt tag

  • GET Request to URL localhost:3443/dishes/ (User Authenticated !)

alt tag

About

Sample Application that Uses JSON web tokens for token-based user authentication.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages