JWT (JSON Web Token)
Introduction to JSON Web Tokens
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and
self-contained way for securely transmitting information between parties as a
JSON object. This information can be verified and trusted because it is
digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a
public/private key pair using RSA or ECDSA.
When should you use JSON Web Tokens?
Here
are some scenarios where JSON Web Tokens are useful:
Authorization: This is the most common
scenario for using JWT. Once the user is logged in, each subsequent request
will include the JWT, allowing the user to access routes, services, and
resources that are permitted with that token. Single Sign On is a feature that
widely uses JWT nowadays, because of its small overhead and its ability to be
easily used across different domains.
Information Exchange: JSON Web Tokens are a good
way of securely transmitting information between parties. Because JWTs can be
signed—for example, using public/private key pairs—you can be sure the senders
are who they say they are. Additionally, as the signature is calculated using
the header and the payload, you can also verify that the content hasn't been
tampered with.
What is the Structure of JSON Web Tokens?
In its compact form, JSON Web Tokens consist of
three parts separated by dots (.), which are:
Header
Payload
Signature
Therefore,
a JWT typically looks like the following.
header.payload.signature
Header
|
Payload
|
Signature
|
Let's
break down the different parts.
Header:
The
header typically consists of two parts: the type of the token, which is
JWT, and the signing algorithm being used, such as HMAC SHA256 or RSA.
Then,
this JSON is Base64Url encoded to form the first part of the
JWT.
Payload:
The
second part of the token is the payload, which contains the claims. Claims are
statements about an entity (typically, the user) and additional data. The
payload is then Base64Url encoded to form the
second part of the JWT.
Set JSON Claims for the JWT with the following
parameters:
Signature
To create the signature part
you have to take the encoded header, the encoded payload, a secret, the
algorithm specified in the header, and sign that.
For example if you want to use the RS 256
algorithm, the signature will be created in the following way:
The
output is three Base64-URL strings separated by dots that can be easily passed
in HTML and HTTP environments. The
following shows a JWT that has the previous header and payload encoded, and it
is signed with a secret.

Thank you for sharing such useful information. I really enjoyed while reading your article and it is good to know the latest updates. Do post more. And also read about leadingSalesforce Service Cloud Consultant
ReplyDelete