JWT
JWT (JSON Web Token) is a compact, URL-safe, self-contained format for securely transmitting information between parties. A JWT includes claims, which are statements about a user or system, and is signed by the server. Clients send the JWT in the Authorization header with each API request, allowing the server to verify the token's authenticity and authorize access based on the claims embedded within it.
Configurations
JWT authentication mechanism has the following configurations:
Explicit Token
An explicit token refers to a token that includes clear, detailed information about the user or entity it represents. In the context of JWTs, it makes the token more self-contained by not relying on the server to retrieve user data based solely on the sub (subject) claim.
Token
The JSON Web Token string containing the signed claims.
Add token as part of the Query Parameter
You can include a token as a query parameter if needed. However, you must use this approach carefully and follow best practices to mitigate security risks.
Add token as part of the Header
JWT is commonly included in the Authorization header of HTTP requests in web applications and APIs to authenticate and authorize users. Sending the JWT in the header enables secure transmission of the token between the client and server.
Add token as part of the Cookie
In JWT authentication mechanisms that use cookies, the cookie key refers to the name or identifier of the cookie that stores the JWT. When the server sends a JWT to the client as a cookie, it specifies this key so that both the client and server know which cookie contains the token and can access or update it as needed.
Dynamic Token
A dynamic token in JWT authentication refers to a token that is generated or updated based on specific conditions, user actions, or contextual requirements. Dynamic tokens provide flexibility in authentication and authorization systems by allowing the token’s contents or validity to adapt to different scenarios.
Configuration
Description
Secret Key
The secret key is essential for securing tokens, including dynamic tokens. It is used to sign the token and to verify its integrity, allowing the server to ensure that the token has not been altered by unauthorized parties.
Algorithm
Select from one of the following:
SHA-1 — A hashing algorithm used to sign JWTs, though Traceable does not recommend it due to known security weaknesses.
SHA-256 — A secure hashing algorithm commonly used to sign JWTs, providing strong integrity protection for token verification.
Add Claim
In JWT, a claim is a piece of information about an entity, usually the user, encoded in the token. Claims convey details, such as the user's identity, token expiration, roles, or permissions. They appear in the token's payload and define the token's purpose and access capabilities.
Claims appear as key-value pairs inside the JWT payload, which is a JSON object. The following is an example of a JWT payload containing claims:
In this example:
The
subclaim identifies the subject (user) as 1234567890.The
nameclaim provides the user's name as John Doe.The
roleclaim specifies that the abovenamehas the role of user.The
expclaim indicates that the token is valid until the timestamp 1632086400.
Example
The following are some samples that you can use to configure the JWT mechanism in the Advanced mode:
Sample 1
Sample 2
Last updated
Was this helpful?