Voiced by Amazon Polly |
Overview
In the ever-evolving landscape of web applications, security is of paramount importance. After successfully authenticating users, web applications must ensure that these users can only access the resources and perform actions appropriate for their roles and privileges. This is where authorization mechanisms come into play. Authorization mechanisms dictate what an authenticated user can or cannot do within a web application, protecting sensitive data and functionality.
A web application must establish whether a user is authorized to access or take specific actions on resources after the user has been authenticated in the application. To confirm that the user has the necessary rights to carry out the desired operations, the authorization process entails reviewing the user’s permissions.
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Introduction
This procedure protects the security and integrity of the application by ensuring that authorized users can only access the resources and carry out actions for which they have permission. That’s where JWT tokens come into play.
When a client submits a username and password for a login request to the server, the server stores the user information in memory, creates an identifier that links to that location, and delivers that identifier as a session identifier (often in browser cookies).
Problems:
- To maintain the session state, traditional session IDs need server-side storage. In distributed systems, this can be resource intensive and difficult to scale.
- Session IDs can be challenging to safely transmit between several domains or APIs due to CORS constraints.
- Managing session state across many servers or instances can be challenging because the data relating to a session ID is saved on the server.
Solution:
- JWT tokens are stateless and contain all relevant data, including user roles and permissions. Servers don’t need to store session data to verify tokens.
- They don’t need to be kept on the server because they already have all the information.
- JWT tokens can be used as a standardized authentication method, enabling users to utilize a single token to access numerous services or APIs.
- The signature is consulted to ascertain whether the client modified the token.
JWT token structure: [HEADER].[𝘗𝘈𝘠𝘓𝘖𝘈𝘋].[𝘚𝘐𝘎𝘕𝘈𝘛𝘜𝘙𝘌]
Header:
- The type of token and the signature procedure are typically the two components of the header. It is base64url and JSON encoded. Typical header components include:
1 2 3 4 |
{ "alg": "HS256", // Signing algorithm (e.g., HMAC SHA-256) "typ": "JWT" // Token type } |
Payload
- The assertions are in the payload. Claims are assertions about a subject (usually the user) and supplementary information. Registered, public, and private claims are the three different categories of claims.
- Registered Claims are predetermined claims that are not required but are advised because they can yield helpful data. The terms “iss” (issuer), “exp” (expiration time), “sub” (subject), and “aud” (audience) are frequently used in registered claims.
- Public Claims are those that you or any other party create and then share with other parties who use JWTs. Simply said, they are namespaced attributes. For instance, “user_id” or “role”.
- Private Claims are specialized claims for information sharing between parties that consent to their use.
1 2 3 4 5 |
{ "sub": "1234567890", "name": "John Doe", "iat": 1516239022 } |
Signature
- The encoded header, encoded payload, a secret (or a public key in the case of asymmetric algorithms), and the algorithm described in the header are the ingredients needed to construct the signature portion. The JWT’s signature is used to confirm that the sender is who they claim to be and to ensure the message hasn’t been altered in transit.
- The signature is made in the following way:
1 2 3 4 5 |
HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), secret ) |
- Alternatively, for asymmetric algorithms (like RSA),
1 2 3 4 5 |
RSASHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), privateKey ) |
The JWT is created by combining the signature with dots, the encoded header and payload, and the encoded payload:
1 |
base64UrlEncode(header) + "." + base64UrlEncode(payload) + "." + signature |
This is how the server verifies the token; it decodes the “header” and “payload,” creates the “new_signature” using the above mentioned algorithm, and then compares the “new_signature” to the “signature” in the JWT token.
Conclusion
JSON online Tokens (JWTs) have completely changed online application security by offering a standardized, effective, and safe user authentication method. Although it has many advantages, like stateless operation and easier access to various services, developers must be aware of potential security flaws. They should emphasize the importance of protecting sensitive data, using reliable encryption techniques, and ensuring that token validation is done correctly. JWTs have greatly improved the authorization procedure, enabling easy access while upholding a robust security posture for web apps.
Drop a query if you have any questions regarding JWT and we will get back to you quickly.
Making IT Networks Enterprise-ready – Cloud Management Services
- Accelerated cloud migration
- End-to-end view of the cloud environment
About CloudThat
CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Premier Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront Service Delivery Partner, Amazon OpenSearch Service Delivery Partner, AWS DMS Service Delivery Partner, AWS Systems Manager Service Delivery Partner, Amazon RDS Service Delivery Partner, AWS CloudFormation Service Delivery Partner, AWS Config, Amazon EMR and many more.
FAQs
1. What does the signature in a JWT serve as?
ANS: – The signature is used to ensure that the token hasn’t been tampered with during transit and to confirm that the sender of the JWT is who they say they are. It offers authentication and data integrity.
2. Can you describe how symmetric and asymmetric JWT signing methods differ?
ANS: – The JWT is signed and verified using the same key with symmetric algorithms. Employing a set of public and private keys is common in asymmetric algorithms. The JWT is signed using the private key and verified using the public key. Asymmetric algorithms offer greater security and are appropriate for circumstances requiring several parties to verify them.
3. What security issues when using JWTs should developers be aware of?
ANS: – Once base64url-decoded, sensitive data in the payload can easily be accessed. Hence, developers should exercise caution when doing so. They should safeguard the JWT secret or keys and guarantee the usage of reliable, well-configured algorithms. Security also depends on token expiration and accurate validation.

WRITTEN BY Ritushree Dutta
Comments