Builder
(builder)
Overview
The JWT Builder
facilitates the creation of JSON Web Tokens by providing methods for setting headers, adding payload claims, and signing the token with a specified algorithm. Its chaining capabilities enable streamlined construction of tokens for secure communication.
Functionality
Headers can be added using the header(key, value)
method, specifying header names and values. Payloads, including claims, can be defined with payload(payload)
or extended using withClaim(key, value)
. For specifying token expiration, the withExpires(expire)
method adds an "exp" claim. The sign(alg)
method finalizes the token by signing it with the chosen algorithm, automatically including the algorithm ("alg") in the header.
Methods Summarized
Adds a header to the JWT token.
Adds the payload (claims) to the web token.
Sign the token with the given algorithm.
Adds data to the payload, which contains the claims.
Add a specific Expires At ("exp") claim to the Payload.
Methods Detailed
header(key, value)
Adds a header to the JWT token.
Parameters
payload(payload)
Adds the payload (claims) to the web token.
Parameters
sign(alg)
Sign the token with the given algorithm. The 'alg' claim is automatically added to the token header.
Parameters
withClaim(key, value)
Adds data to the payload, which contains the claims. Claims are statements about an entity (typically, the user) and additional data.
Parameters
withExpires(expire)
Add a specific Expires At ("exp") claim to the Payload.
Parameters
Last updated
Was this helpful?