jwt
(plugins.jwt)
Overview
The JWT
plugin facilitates operations involving JSON Web Tokens, such as creating, signing, and verifying tokens. It provides various algorithms, including SHA256
, SHA384
, and SHA512
in combination with ECDSA
or RSA
, allowing flexible cryptographic operations. These algorithms can be configured with public and private keys for signing and verification, or with shared secrets for symmetric encryption.
Developers can use the builder()
method to create tokens dynamically by specifying payloads and signing them with a chosen algorithm. Alternatively, simplified methods are available, like create(payload)
or create(payload, expiresAt)
, which use pre-configured HmacSHA256
algorithms and shared secret keys for signing.
Token verification can be performed using verify(token)
for default algorithms or verify(token, algorithm)
for custom cryptographic configurations. The plugin also supports building algorithms based on external JSON Web Key Sets (JWKS) using the JWK(url)
method. These features collectively enable robust and secure token-based authentication systems.
Returned Types
Methods Summarized
Builder to create a new Algorithm instance using SHA256withECDSA.
Builder to create a new Algorithm instance using SHA256withECDSA.
Builder to create a new Algorithm instance using SHA384withECDSA.
Builder to create a new Algorithm instance using SHA384withECDSA.
Builder to create a new Algorithm instance using SHA512withECDSA.
Builder to create a new Algorithm instance using SHA512withECDSA.
Builder to create a new Algorithm instance using SHA256withRSA.
Builder to create a new Algorithm instance using SHA256withRSA.
Builder to create a new Algorithm instance using SHA384withRSA.
Builder to create a new Algorithm instance using SHA384withRSA.
Builder to create a new Algorithm instance using SHA512withRSA.
Builder to create a new Algorithm instance using SHA512withRSA.
Create a JSON Web Token for the given payload that is signed with the (shared) secret key 'jwt.
Create a JSON Web Token for the given payload that is signed with the HS256 algorithm and the (shared) secret key 'jwt.
Verify a JSON Web Token with the HS256 algorithm and the (shared) secret key 'jwt.
Methods Detailed
ES256(publicKey)
Builder to create a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256".
Parameters
Array publicKey a byte array representing the publicKey (mostly used to verify tokens)
Returns: Algorithm an algorithm builder used to sign or verify JSON Web Tokens.
ES256(publicKey, privateKey)
Builder to create a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256".
Parameters
Array publicKey a byte array representing the publicKey (mostly used to verify tokens)
Array privateKey a byte array representing the privateKey (mostly used to create tokens)
Returns: Algorithm an algorithm used to sign or verify JSON Web Tokens.
ES256(publicKey)
Builder to create a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256".
Parameters
String publicKey a String representing the publicKey (mostly used to verify tokens)
Returns: Algorithm an algorithm builder used to sign or verify JSON Web Tokens.
Sample
ES256(publicKey, privateKey)
Builder to create a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256".
Parameters
String publicKey a String representing the publicKey (mostly used to verify tokens)
String privateKey a String representing the privateKey (mostly used to create tokens) The private key is assumed to be encoded according to the PKCS #8 standard.
Returns: Algorithm an algorithm used to sign or verify JSON Web Tokens.
Sample
ES384(publicKey)
Builder to create a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384".
Parameters
Array publicKey a byte array representing the publicKey (mostly used to verify tokens)
Returns: Algorithm an algorithm builder used to sign or verify JSON Web Tokens.
ES384(publicKey, privateKey)
Builder to create a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384".
Parameters
Array publicKey a byte array representing the publicKey (mostly used to verify tokens)
Array privateKey a byte array representing the privateKey (mostly used to create tokens)
Returns: Algorithm an algorithm used to sign or verify JSON Web Tokens.
ES384(publicKey)
Builder to create a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384".
Parameters
String publicKey a String representing the publicKey (mostly used to verify tokens)
Returns: Algorithm an algorithm builder used to sign or verify JSON Web Tokens.
Sample