Coder Social home page Coder Social logo

nodejs-auth-boilerplate's Introduction

This is a very minimal boilterplate for implementing authentication and authorization in Node-Express API.

  • Secure: Built with security in mind. Anti XSS and CSRF attacks.
  • Feature Rich: Includes all the essential features like password reset, password recovery, logout of everywhere and remember me.
  • Scalable: Contains only the bare bones so, can be used as the ground for projects.
  1. Sign up
 POST /auth/signup
 Content-Type:  application/json
 {
 "email":  "[email protected]",
 "password":  "Year2021"
 }
  1. Login
  POST /auth/signup
  Content-Type:  application/json
  {
  "email":  "[email protected]",
  "password":  "Year2021",
  "remember_me": true
  }
  1. Logout
 GET /auth/logout
 Authorization: Bearer <access_token>
  1. New Access Token
 GET /auth/token
 Authorization: Bearer <access_token>
  1. Request Password Reset
  POST /auth/request-reset-password
  Content-Type:  application/json
  {
    "email": "[email protected]"
  }
  1. Change password
  POST /auth/user/update/password
  Content-Type:  application/json
  Authorization: Bearer <access_token>
 {
   "password": "Year2022"
 }
  1. How are CSRF attacks handled?

    Only refresh token is stored in cookie. All the end points (except token refresh) accept only access token (which is advised to store in memory by client). So, attacker can't forge a false request on behalf of client.

  2. How are XSS attacks handled?

    Clients are advised to store the access token in memory to avoid XSS attacks.

  3. How to handle token refreshing in client side?

    When a user logs in or signs up, an access token and it's expiry date is send by the api in the response. The client can do silent refresh by checking the expiry date to avoid interrupting the user.

  4. What if an attacker tries to get access token through a CSRF attack?

    Since, the refresh token is stored in cookies, the attacker can definitely make a request to get an access token using the refresh token. However, this can be mitigated by using CORS policy. This way, even if the attacker makes false request, he won't get the response.

nodejs-auth-boilerplate's People

Contributors

kcsujeet avatar iamshaunjp avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.