JSON Web Token
JSON Web Token (JWT, pronounced , same as the word "jot") is a proposed Internet standard for creating data with optional signature and/or optional encryption whose payload holds JSON that asserts some number of claims. The tokens are signed either using a private secret or a public/private key.

For example, a server could generate a token that has the claim "logged in as administrator" and provide that to a client. The client could then use that token to prove that it is logged in as admin. The tokens can be signed by one party's private key (usually the server's) so that party can subsequently verify the token is legitimate. If the other party, by some suitable and trustworthy means, is in possession of the corresponding public key, they too are able to verify the token's legitimacy. The tokens are designed to be compact, URL-safe, and usable especially in a web-browser single-sign-on (SSO) context. JWT claims can typically be used to pass identity of authenticated users between an identity provider and a service provider, or any other type of claims as required by business processes.

JWT relies on other JSON-based standards: JSON Web Signature and JSON Web Encryption.

Structure

The three parts are encoded separately using Base64url Encoding , and concatenated using periods to produce the JWT:
const token = base64urlEncoding(header) + '.' + base64urlEncoding(payload) + '.' + base64urlEncoding(signature)

The above data and the secret of "secretkey" creates the token:

This resulting token can be easily passed into HTML and HTTP.

Use 
In authentication, when the user successfully logs in using their credentials, a JSON Web Token will be returned and must be saved locally (typically in local or session storage, but cookies can also be used), instead of the traditional approach of creating a session in the server and returning a cookie. For unattended processes the client may also authenticate directly by generating and signing its own JWT with a pre-shared secret and pass it to a OAuth compliant service like so:POST /oauth2/token?
Content-type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=eyJhb...If the client passes a valid JWT assertion the server will generate an access_token valid for making calls to the application and pass it back to the client:{
  "access_token": "eyJhb...",
  "token_type": "Bearer",
  "expires_in": 3600
}When the client wants to access a protected route or resource, the user agent should send the JWT, typically in the Authorization header using the Bearer schema. The content of the header might look like the following:
 Authorization: Bearer eyJhbGci...<snip>...yu5CSpyHI
This is a stateless authentication mechanism as the user state is never saved in server memory. The server's protected routes will check for a valid JWT in the Authorization header, and if it is present, the user will be allowed to access protected resources. As JWTs are self-contained, all the necessary information is there, reducing the need to query the database multiple times.

Standard fields

Implementations 
JWT implementations exist for many languages and frameworks, including but not limited to:

.NET (C# VB.Net etc)
C
Clojure
Common Lisp
 Dart
Elixir
 Erlang
Go
Haskell
Java
JavaScript
Lua
 Node.js
OCaml
Perl
PHP
PL/SQL
PowerShell
Python
Racket
Raku
Ruby
Rust 
Scala
Swift

Vulnerabilities
JSON web tokens may contain session state. But if project requirements allow session invalidation before JWT expiration, services can no longer trust token assertions by the token alone. To validate that the session stored in the token is not revoked, token assertions must be checked against a data store. This renders the tokens no longer stateless, undermining the primary advantage of JWTs.

Security consultant Tim McLean reported vulnerabilities in some JWT libraries that used the alg field to incorrectly validate tokens, most commonly by accepting a alg=none token. While these vulnerabilities were patched, McLean suggested deprecating the alg field altogether to prevent similar implementation confusion. Still, new alg=none vulnerabilities are still being found in the wild, with four CVEs filed in the 2018-2021 period having this cause.

With proper design, developers can address algorithm vulnerabilities by taking precautions:

 Never let the JWT header alone drive verification
 Know the algorithms (avoid depending on the  field alone)
 Use an appropriate key size

See also
Access token

References

External links
 
 jwt.io – specialized website about JWT with tools and documentation, maintained by Auth0
 Spring Boot JWT Auth – Integrating JWT authentication with Spring framework
 JWT Security – JWT Security e-Book PDF (Polish language)
 Why do we need JWT in the modern web - a detailed article on the topic with some historical considerations
 How To install JWT Auth in laravel - Article with installation steps of JWT Auth

Computer access control
Identity management
Federated identity
Identity management systems
Metadata standards
JSON