Giter Club home page Giter Club logo

jwt-authentication's Introduction

๐Ÿ” JWT Authentication

Project Objectives

Developing an understanding of the differences between session based authenticaion and JSON Web Token (JWT) authenticaiton by implementing express-jwt in a simple project

What does JTW Look Like?

Three strings separated by a period. Each section has a unique significance.

  1. Header: Typically consists of two parts: token type and hashing algorithm
  2. Payload: Contains claims about entity & other data. Three types of claims: registered, public, and private.
  3. Signature: Created by taking encoded header & payload, a secret, algorithm from header and signing all that.
  aaaaaaaaaa.bbbbbbbbbbb.cccccccccccc

Output

The output is three Base64-URL strings that can easily by passed in HTML and HTTP environments.
It might look something like this:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzY290Y2guaW8iLCJleHAiOjEzMDA4MTkzODAsIm5hbWUiOiJDaHJpcyBTZXZpbGxlamEiLCJhZG1pbiI6dHJ1ZX0.03f329983b86f7d9a9f5fef85305880101d5e302afafa20154d094b229f75773

Authentication Process

  1. Client sends a request for authentication
  2. The server receives credentials
  • Token is a hash
  • Token contains a secret key
  • Secret key can only be unencrypted by server
  1. The client includes token whenever requesting restricted resources
  2. The server verifies token with each request

Benefits of JWT

  • No sessions required
  • Simply saves token to client
  • Sent instead of CSRF token
  • As long as JWT valid, data on route!
  • Super fast, no need to look up session
  • Better storage, don't have to store session
  • Mobile Ready b/c apps can save auth tokens
  • Testing is unnecessary, just send token

jwt-authentication's People

Contributors

anniepawl avatar

Watchers

 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.