SlideShare a Scribd company logo
1 of 19
Download to read offline
5 Easy Steps to Understanding JSON
Web Tokens (JWT)
In this article, the fundamentals of what JSON Web Tokens (JWT) are,
and why they are used will be explained. JWT are an important piece in
ensuring trust and security in your application. JWT allow claims, such
as user data, to be represented in a secure manner.
To explain how JWT work, let’s begin with an abstract definition.
A JSON Web Token (JWT) is a JSON object that is
defined in RFC 7519 as a safe way to represent a set
Mikey Stecky-Efantis Follow
May 16, 2016 · 7 min read
of information between two parties. The token is
composed of a header, a payload, and a signature.
Simply put, a JWT is just a string with the following format:
header.payload.signature
It should be noted that a double quoted string is actually considered a valid
JSON object.
To show how and why JWT are actually used, we will use a simple 3
entity example (see the below diagram). The entities in this example
are the user, the application server, and the authentication server. The
authentication server will provide the JWT to the user. With the JWT,
the user can then safely communicate with the application.
In this example, the user first signs into the authentication server using
the authentication server’s login system (e.g. username and password,
How an application uses JWT to verify the authenticity of a user.
Facebook login, Google login, etc). The authentication server then
creates the JWT and sends it to the user. When the user makes API calls
to the application, the user passes the JWT along with the API call. In
this setup, the application server would be configured to verify that the
incoming JWT are created by the authentication server (the
verification process will be explained in more detail later). So, when
the user makes API calls with the attached JWT, the application can use
the JWT to verify that the API call is coming from an authenticated
user.
Now, the JWT itself, and how it’s constructed and verified, will be
examined in more depth.
Step 1. Create the HEADER
The header component of the JWT contains information about how the
JWT signature should be computed. The header is a JSON object in the
following format:
In this JSON, the value of the “typ” key specifies that the object is a
JWT, and the value of the “alg” key specifies which hashing algorithm
is being used to create the JWT signature component. In our example,
we’re using the HMAC-SHA256 algorithm, a hashing algorithm that
uses a secret key, to compute the signature (discussed in more detail in
step 3).
Step 2. Create the PAYLOAD
The payload component of the JWT is the data that‘s stored inside the
JWT (this data is also referred to as the “claims” of the JWT). In our
example, the authentication server creates a JWT with the user
information stored inside of it, specifically the user ID.
1
2
3
4
{
"typ": "JWT",
"alg": "HS256"
}
In our example, we are only putting one claim into the payload. You can
put as many claims as you like. There are several different standard
claims for the JWT payload, such as “iss” the issuer, “sub” the subject,
and “exp” the expiration time. These fields can be useful when creating
JWT, but they are optional. See the wikipedia page on JWT for a more
detailed list of JWT standard fields.
Keep in mind that the size of the data will affect the overall size of the
JWT, this generally isn’t an issue but having excessively large JWT may
negatively affect performance and cause latency.
Step 3. Create the SIGNATURE
1
2
3
{
"userId": "b08f86af-35da-48f2-8fab-cef3904660bd"
}
The data inside the payload is referred to as the “claims” of the token.
The signature is computed using the following pseudo code:
// signature algorithm
data = base64urlEncode( header ) + “.” + base64urlEncode(
payload )
hashedData = hash( data, secret )
signature = base64urlEncode( hashedData )
What this algorithm does is base64url encodes the header and the
payload created in steps 1 and 2. The algorithm then joins the resulting
encoded strings together with a period (.) in between them. In our
pseudo code, this joined string is assigned to data. The data string is
hashed with the secret key using the hashing algorithm specified in the
JWT header. The resulting hashed data is assigned to hashedData. This
hashed data is then base64url encoded to produce the JWT signature.
In our example, both the header, and the payload are base64url
encoded as:
// header
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9
// payload
eyJ1c2VySWQiOiJiMDhmODZhZi0zNWRhLTQ4ZjItOGZhYi1jZWYzOTA0NjYw
YmQifQ
Then, applying the specified signature algorithm with the secret key on
the period-joined encoded header and encoded payload, we get the
hashed data needed for the signature. In our case, this means applying
the HS256 algorithm, with the secret key set as the string “secret”, on
the data string to get the hashedData string. After, through base64url
encoding the hashedData string we get the following JWT signature:
// signature
-xN_h82PHVTCMA9vdoHrcZxH-x5mb11y1537t3rGzcM
Step 4. Put All Three JWT Components
Together
Now that we have created all three components, we can create the
JWT. Remembering the header.payload.signature structure of the JWT,
we simply need to combine the components, with periods (.)
separating them. We use the base64url encoded versions of the header
and of the payload, and the signature we arrived at in step 3.
// JWT Token
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJiMDhmODZ
hZi0zNWRhLTQ4ZjItOGZhYi1jZWYzOTA0NjYwYmQifQ.-
xN_h82PHVTCMA9vdoHrcZxH-x5mb11y1537t3rGzcM
You can try creating your own JWT through your browser at jwt.io.
Going back to our example, the authentication server can now send this
JWT to the user.
How does JWT protect our data?
It is important to understand that the purpose of using JWT is NOT to
hide or obscure data in any way. The reason why JWT are used is to
prove that the sent data was actually created by an authentic source.
As demonstrated in the previous steps, the data inside a JWT is
encoded and signed, not encrypted. The purpose of encoding data is
to transform the data’s structure. Signing data allows the data receiver
to verify the authenticity of the source of the data. So encoding and
signing data does NOT secure the data. On the other hand, the main
purpose of encryption is to secure the data and to prevent
unauthorized access. For a more detailed explanation of the differences
between encoding and encryption, and also for more information on
how hashing works, see this article.
Since JWT are signed and encoded only, and since
JWT are not encrypted, JWT do not guarantee any
security for sensitive data.
Step 5. Verifying the JWT
In our simple 3 entity example, we are using a JWT that is signed by the
HS256 algorithm where only the authentication server and the
application server know the secret key. The application server receives
the secret key from the authentication server when the application sets
up its authentication process. Since the application knows the secret
key, when the user makes a JWT-attached API call to the application,
the application can perform the same signature algorithm as in Step 3
on the JWT. The application can then verify that the signature obtained
from it’s own hashing operation matches the signature on the JWT
itself (i.e. it matches the JWT signature created by the authentication
server). If the signatures match, then that means the JWT is valid
which indicates that the API call is coming from an authentic source.
Otherwise, if the signatures don’t match, then it means that the
received JWT is invalid, which may be an indicator of a potential attack
on the application. So by verifying the JWT, the application adds a
layer of trust between itself and the user.
In Conclusion
We went over what JWT are, how they are created and validated, and
how they can be used to ensure trust between an application and its
users. This is a starting point for understanding the fundamentals of
JWT and why they are useful. JWT are just one piece of the puzzle in
ensuring trust and security in your application.
. . .
It should be noted that the JWT authentication setup described in this
article is using a symmetric key algorithm (HS256). You can also set up
your JWT authentication in a similar way except using an asymmetric
algorithm (such as RS256) where the authentication server has a secret
key, and the application server has a public key. Check out this Stack
Overflow question for a detailed breakdown of the differences between
using symmetric and asymmetric algorithms.
It should also be noted that JWT should be sent over HTTPS
connections (not HTTP). Having HTTPS helps prevents unauthorized
users from stealing the sent JWT by making it so that the
communication between the servers and the user cannot be
intercepted .
Also, having an expiration in your JWT payload, a short one in
particular, is important so that if old JWT ever get compromised, they
will be considered invalid and can no longer be used.
. . .
If you enjoyed this article and are writing handlers for AWS Lambda
and are implementing JWT, please check out our project: Vandium
Vandium: The Node.js Framework for AWS
Lamba
 
One of the most exciting new cloud technologies
over the last few years has been the emergence …
medium.com
Landscape
Landscape
Landscape

More Related Content

Similar to Landscape

Introduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring SecurityIntroduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring SecurityBruno Henrique Rother
 
Uniface Lectures Webinar - Application & Infrastructure Security - JSON Web T...
Uniface Lectures Webinar - Application & Infrastructure Security - JSON Web T...Uniface Lectures Webinar - Application & Infrastructure Security - JSON Web T...
Uniface Lectures Webinar - Application & Infrastructure Security - JSON Web T...Uniface
 
Using JSON Web Tokens for REST Authentication
Using JSON Web Tokens for REST Authentication Using JSON Web Tokens for REST Authentication
Using JSON Web Tokens for REST Authentication Mediacurrent
 
Jwt with flask slide deck - alan swenson
Jwt with flask   slide deck - alan swensonJwt with flask   slide deck - alan swenson
Jwt with flask slide deck - alan swensonJeffrey Clark
 
Understanding JWT Exploitation
Understanding JWT ExploitationUnderstanding JWT Exploitation
Understanding JWT ExploitationAkshaeyBhosale
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationWebStackAcademy
 
Microservices Security Patterns & Protocols with Spring & PCF
Microservices Security Patterns & Protocols with Spring & PCFMicroservices Security Patterns & Protocols with Spring & PCF
Microservices Security Patterns & Protocols with Spring & PCFVMware Tanzu
 
How Does Signing & Validating a JSON Web Tokens Work
How Does Signing & Validating a JSON Web Tokens WorkHow Does Signing & Validating a JSON Web Tokens Work
How Does Signing & Validating a JSON Web Tokens WorkRohit Jacob Mathew
 
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API ManagerWSO2
 
Survey on An effective database tampering system with veriable computation a...
Survey on An effective  database tampering system with veriable computation a...Survey on An effective  database tampering system with veriable computation a...
Survey on An effective database tampering system with veriable computation a...IRJET Journal
 
Introducing Blockchain with Java Program, Imple.pdf
Introducing Blockchain with Java Program, Imple.pdfIntroducing Blockchain with Java Program, Imple.pdf
Introducing Blockchain with Java Program, Imple.pdfhind400342
 
IRJET- Improved Vault based Tokenization to Boost Vault Lookup Performance
IRJET-  	  Improved Vault based Tokenization to Boost Vault Lookup PerformanceIRJET-  	  Improved Vault based Tokenization to Boost Vault Lookup Performance
IRJET- Improved Vault based Tokenization to Boost Vault Lookup PerformanceIRJET Journal
 

Similar to Landscape (20)

Introduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring SecurityIntroduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring Security
 
Json web tokens
Json web tokensJson web tokens
Json web tokens
 
JSON WEB TOKEN
JSON WEB TOKENJSON WEB TOKEN
JSON WEB TOKEN
 
Jwt Security
Jwt SecurityJwt Security
Jwt Security
 
Uniface Lectures Webinar - Application & Infrastructure Security - JSON Web T...
Uniface Lectures Webinar - Application & Infrastructure Security - JSON Web T...Uniface Lectures Webinar - Application & Infrastructure Security - JSON Web T...
Uniface Lectures Webinar - Application & Infrastructure Security - JSON Web T...
 
Using JSON Web Tokens for REST Authentication
Using JSON Web Tokens for REST Authentication Using JSON Web Tokens for REST Authentication
Using JSON Web Tokens for REST Authentication
 
Json web tokens
Json web tokensJson web tokens
Json web tokens
 
Jwt with flask slide deck - alan swenson
Jwt with flask   slide deck - alan swensonJwt with flask   slide deck - alan swenson
Jwt with flask slide deck - alan swenson
 
Understanding JWT Exploitation
Understanding JWT ExploitationUnderstanding JWT Exploitation
Understanding JWT Exploitation
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
 
JWTs and JOSE in a flash
JWTs and JOSE in a flashJWTs and JOSE in a flash
JWTs and JOSE in a flash
 
Microservices Security Patterns & Protocols with Spring & PCF
Microservices Security Patterns & Protocols with Spring & PCFMicroservices Security Patterns & Protocols with Spring & PCF
Microservices Security Patterns & Protocols with Spring & PCF
 
How Does Signing & Validating a JSON Web Tokens Work
How Does Signing & Validating a JSON Web Tokens WorkHow Does Signing & Validating a JSON Web Tokens Work
How Does Signing & Validating a JSON Web Tokens Work
 
Json Web Token - JWT
Json Web Token - JWTJson Web Token - JWT
Json Web Token - JWT
 
Restful api
Restful apiRestful api
Restful api
 
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
 
Securing RESTful API
Securing RESTful APISecuring RESTful API
Securing RESTful API
 
Survey on An effective database tampering system with veriable computation a...
Survey on An effective  database tampering system with veriable computation a...Survey on An effective  database tampering system with veriable computation a...
Survey on An effective database tampering system with veriable computation a...
 
Introducing Blockchain with Java Program, Imple.pdf
Introducing Blockchain with Java Program, Imple.pdfIntroducing Blockchain with Java Program, Imple.pdf
Introducing Blockchain with Java Program, Imple.pdf
 
IRJET- Improved Vault based Tokenization to Boost Vault Lookup Performance
IRJET-  	  Improved Vault based Tokenization to Boost Vault Lookup PerformanceIRJET-  	  Improved Vault based Tokenization to Boost Vault Lookup Performance
IRJET- Improved Vault based Tokenization to Boost Vault Lookup Performance
 

Recently uploaded

Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailAriel592675
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,noida100girls
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCRashishs7044
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607dollysharma2066
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...lizamodels9
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...lizamodels9
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Servicecallgirls2057
 
Call Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any TimeCall Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any Timedelhimodelshub1
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...lizamodels9
 
Islamabad Escorts | Call 03274100048 | Escort Service in Islamabad
Islamabad Escorts | Call 03274100048 | Escort Service in IslamabadIslamabad Escorts | Call 03274100048 | Escort Service in Islamabad
Islamabad Escorts | Call 03274100048 | Escort Service in IslamabadAyesha Khan
 
The CMO Survey - Highlights and Insights Report - Spring 2024
The CMO Survey - Highlights and Insights Report - Spring 2024The CMO Survey - Highlights and Insights Report - Spring 2024
The CMO Survey - Highlights and Insights Report - Spring 2024christinemoorman
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfJos Voskuil
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...lizamodels9
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxMarkAnthonyAurellano
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...ictsugar
 
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,noida100girls
 

Recently uploaded (20)

Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detail
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
 
Call Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any TimeCall Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any Time
 
Japan IT Week 2024 Brochure by 47Billion (English)
Japan IT Week 2024 Brochure by 47Billion (English)Japan IT Week 2024 Brochure by 47Billion (English)
Japan IT Week 2024 Brochure by 47Billion (English)
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
 
Islamabad Escorts | Call 03274100048 | Escort Service in Islamabad
Islamabad Escorts | Call 03274100048 | Escort Service in IslamabadIslamabad Escorts | Call 03274100048 | Escort Service in Islamabad
Islamabad Escorts | Call 03274100048 | Escort Service in Islamabad
 
The CMO Survey - Highlights and Insights Report - Spring 2024
The CMO Survey - Highlights and Insights Report - Spring 2024The CMO Survey - Highlights and Insights Report - Spring 2024
The CMO Survey - Highlights and Insights Report - Spring 2024
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdf
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
 
Corporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information TechnologyCorporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information Technology
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
 
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
 

Landscape

  • 1.
  • 2. 5 Easy Steps to Understanding JSON Web Tokens (JWT) In this article, the fundamentals of what JSON Web Tokens (JWT) are, and why they are used will be explained. JWT are an important piece in ensuring trust and security in your application. JWT allow claims, such as user data, to be represented in a secure manner. To explain how JWT work, let’s begin with an abstract definition. A JSON Web Token (JWT) is a JSON object that is defined in RFC 7519 as a safe way to represent a set Mikey Stecky-Efantis Follow May 16, 2016 · 7 min read
  • 3. of information between two parties. The token is composed of a header, a payload, and a signature. Simply put, a JWT is just a string with the following format: header.payload.signature It should be noted that a double quoted string is actually considered a valid JSON object. To show how and why JWT are actually used, we will use a simple 3 entity example (see the below diagram). The entities in this example are the user, the application server, and the authentication server. The authentication server will provide the JWT to the user. With the JWT, the user can then safely communicate with the application.
  • 4. In this example, the user first signs into the authentication server using the authentication server’s login system (e.g. username and password, How an application uses JWT to verify the authenticity of a user.
  • 5. Facebook login, Google login, etc). The authentication server then creates the JWT and sends it to the user. When the user makes API calls to the application, the user passes the JWT along with the API call. In this setup, the application server would be configured to verify that the incoming JWT are created by the authentication server (the verification process will be explained in more detail later). So, when the user makes API calls with the attached JWT, the application can use the JWT to verify that the API call is coming from an authenticated user. Now, the JWT itself, and how it’s constructed and verified, will be examined in more depth. Step 1. Create the HEADER The header component of the JWT contains information about how the JWT signature should be computed. The header is a JSON object in the following format:
  • 6. In this JSON, the value of the “typ” key specifies that the object is a JWT, and the value of the “alg” key specifies which hashing algorithm is being used to create the JWT signature component. In our example, we’re using the HMAC-SHA256 algorithm, a hashing algorithm that uses a secret key, to compute the signature (discussed in more detail in step 3). Step 2. Create the PAYLOAD The payload component of the JWT is the data that‘s stored inside the JWT (this data is also referred to as the “claims” of the JWT). In our example, the authentication server creates a JWT with the user information stored inside of it, specifically the user ID. 1 2 3 4 { "typ": "JWT", "alg": "HS256" }
  • 7. In our example, we are only putting one claim into the payload. You can put as many claims as you like. There are several different standard claims for the JWT payload, such as “iss” the issuer, “sub” the subject, and “exp” the expiration time. These fields can be useful when creating JWT, but they are optional. See the wikipedia page on JWT for a more detailed list of JWT standard fields. Keep in mind that the size of the data will affect the overall size of the JWT, this generally isn’t an issue but having excessively large JWT may negatively affect performance and cause latency. Step 3. Create the SIGNATURE 1 2 3 { "userId": "b08f86af-35da-48f2-8fab-cef3904660bd" } The data inside the payload is referred to as the “claims” of the token.
  • 8. The signature is computed using the following pseudo code: // signature algorithm data = base64urlEncode( header ) + “.” + base64urlEncode( payload ) hashedData = hash( data, secret ) signature = base64urlEncode( hashedData ) What this algorithm does is base64url encodes the header and the payload created in steps 1 and 2. The algorithm then joins the resulting encoded strings together with a period (.) in between them. In our pseudo code, this joined string is assigned to data. The data string is hashed with the secret key using the hashing algorithm specified in the
  • 9. JWT header. The resulting hashed data is assigned to hashedData. This hashed data is then base64url encoded to produce the JWT signature. In our example, both the header, and the payload are base64url encoded as: // header eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9 // payload eyJ1c2VySWQiOiJiMDhmODZhZi0zNWRhLTQ4ZjItOGZhYi1jZWYzOTA0NjYw YmQifQ Then, applying the specified signature algorithm with the secret key on the period-joined encoded header and encoded payload, we get the hashed data needed for the signature. In our case, this means applying the HS256 algorithm, with the secret key set as the string “secret”, on
  • 10. the data string to get the hashedData string. After, through base64url encoding the hashedData string we get the following JWT signature: // signature -xN_h82PHVTCMA9vdoHrcZxH-x5mb11y1537t3rGzcM Step 4. Put All Three JWT Components Together Now that we have created all three components, we can create the JWT. Remembering the header.payload.signature structure of the JWT, we simply need to combine the components, with periods (.) separating them. We use the base64url encoded versions of the header and of the payload, and the signature we arrived at in step 3.
  • 11. // JWT Token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJiMDhmODZ hZi0zNWRhLTQ4ZjItOGZhYi1jZWYzOTA0NjYwYmQifQ.- xN_h82PHVTCMA9vdoHrcZxH-x5mb11y1537t3rGzcM You can try creating your own JWT through your browser at jwt.io. Going back to our example, the authentication server can now send this JWT to the user. How does JWT protect our data? It is important to understand that the purpose of using JWT is NOT to hide or obscure data in any way. The reason why JWT are used is to prove that the sent data was actually created by an authentic source. As demonstrated in the previous steps, the data inside a JWT is encoded and signed, not encrypted. The purpose of encoding data is
  • 12. to transform the data’s structure. Signing data allows the data receiver to verify the authenticity of the source of the data. So encoding and signing data does NOT secure the data. On the other hand, the main purpose of encryption is to secure the data and to prevent unauthorized access. For a more detailed explanation of the differences between encoding and encryption, and also for more information on how hashing works, see this article. Since JWT are signed and encoded only, and since JWT are not encrypted, JWT do not guarantee any security for sensitive data. Step 5. Verifying the JWT In our simple 3 entity example, we are using a JWT that is signed by the HS256 algorithm where only the authentication server and the application server know the secret key. The application server receives
  • 13. the secret key from the authentication server when the application sets up its authentication process. Since the application knows the secret key, when the user makes a JWT-attached API call to the application, the application can perform the same signature algorithm as in Step 3 on the JWT. The application can then verify that the signature obtained from it’s own hashing operation matches the signature on the JWT itself (i.e. it matches the JWT signature created by the authentication server). If the signatures match, then that means the JWT is valid which indicates that the API call is coming from an authentic source. Otherwise, if the signatures don’t match, then it means that the received JWT is invalid, which may be an indicator of a potential attack on the application. So by verifying the JWT, the application adds a layer of trust between itself and the user. In Conclusion We went over what JWT are, how they are created and validated, and how they can be used to ensure trust between an application and its
  • 14. users. This is a starting point for understanding the fundamentals of JWT and why they are useful. JWT are just one piece of the puzzle in ensuring trust and security in your application. . . . It should be noted that the JWT authentication setup described in this article is using a symmetric key algorithm (HS256). You can also set up your JWT authentication in a similar way except using an asymmetric algorithm (such as RS256) where the authentication server has a secret key, and the application server has a public key. Check out this Stack Overflow question for a detailed breakdown of the differences between using symmetric and asymmetric algorithms. It should also be noted that JWT should be sent over HTTPS connections (not HTTP). Having HTTPS helps prevents unauthorized users from stealing the sent JWT by making it so that the
  • 15. communication between the servers and the user cannot be intercepted . Also, having an expiration in your JWT payload, a short one in particular, is important so that if old JWT ever get compromised, they will be considered invalid and can no longer be used. . . . If you enjoyed this article and are writing handlers for AWS Lambda and are implementing JWT, please check out our project: Vandium Vandium: The Node.js Framework for AWS Lamba   One of the most exciting new cloud technologies over the last few years has been the emergence …