Giter VIP home page Giter VIP logo

express_csrf_jwt_study's Introduction

express_csrf_jwt_study - A study about JWT Authentication along with CSRF prevention on Node.js Express

In this study, CSRF prevention and authentication with JWT are implemented with a simple example regardless of database and front-end implementations. HTTP requests were handled through Postman.

  • Sign out function and token invalidation has been added.

Dev Dependencies:

nodemon: A tool that helps develop node.js based applications by restarting automatically the application when file changes are detected in the directory.

Dependencies:

csurf: A Node.js middleware that is used to prevent CSRF attacks. (Note: Note: This module has been deprecated since September 2022 due to the security vulnerability reports. https://github.com/expressjs/csurf)

dotenv: A module for environmental configuration variables.

express: A backend web application framework for Node.js.

express-session: A session middleware for Express.

jsonwebtoken: An implementation of JWT for Node.js.

node-cache: A simple caching module for Node.js that has set, get and delete methods.

.env variables

There should be a .env file in ./backend and its variables are;

DOMAIN
PORT
CSRFT_SESSION_SECRET
JWT_SECRET
#jwt and csrf token expires in milliseconds
CSRFT_EXPIRESIN
JWT_EXPIRESIN
JWT_REFRESH_EXPIRESIN

User credentials

Authentication credentials are not required. They were given manually in the code.

const user = {
    "_id": "someId123", "email": "[email protected]"
} // user data is assigned manually for testing.

Package Installation

cd backend
npm install

Usage

npm run start:dev

express_csrf_jwt_study's People

Contributors

kbrk avatar dependabot[bot] 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.