pdk.util.JWT

functions to operate with JSON web tokens

Functions


generateToken

Actually builds the JWT and serializes it to a compact, URL-safe string according to the JWT Compact Serialization rules. HS512 is using to sign.

Arguments:

Result:

Possible exceptions


generateUserTokenWithAlgo

Actually builds the JWT and serializes it to a compact, URL-safe string according to the JWT Compact Serialization rules.

Supported signature algorithms:

ValueDigital Signature or MAC Algorithm

HS256

HMAC using SHA-256

HS384

HMAC using SHA-384

HS512

HMAC using SHA-512

RS256

RSASSA-PKCS-v1_5 using SHA-256

RS384

RSASSA-PKCS-v1_5 using SHA-384

RS512

RSASSA-PKCS-v1_5 using SHA-512

ES256

ECDSA using P-256 and SHA-256

ES384

ECDSA using P-384 and SHA-384

ES512

ECDSA using P-521 and SHA-512

PS256

RSASSA-PSS using SHA-256 and MGF1 with SHA-256

PS384

RSASSA-PSS using SHA-384 and MGF1 with SHA-384

PS512

RSASSA-PSS using SHA-512 and MGF1 with SHA-512

none

No digital signature or MAC performed

Arguments:

Result:

Possible exceptions

  • NullPointerException - throws if the user, term, secret or signatureAlgorithm argument is NULL

  • SignatureException - throws if the unsupported signature algorithm was defined


validateToken

Verify the token belongs to the input JwtUser.

Arguments:

Result:

Possible exceptions


isTokenExpired

Verify the token has been expired.

Arguments:

Result:

Possible exceptions


getUserIdFromToken

Returns the userId attribute from the serialized jwt token.

Arguments:

Result:

Possible exceptions


getUserFromToken

Returns the user as an object from the serialized jwt token.

Arguments:

Result:

Possible exceptions


getExpirationDateFromToken

Returns the expiration date from the serialized jwt token.

Arguments:

Result:

Possible exceptions


generateTokenWithPayload (since 5.0.5.3 version)

Actually builds the JWT and serializes it to a compact, URL-safe string according to the JWT Compact Serialization rules.

Supported signature algorithms:

ValueDigital Signature or MAC Algorithm

HS256

HMAC using SHA-256

HS384

HMAC using SHA-384

HS512

HMAC using SHA-512

RS256

RSASSA-PKCS-v1_5 using SHA-256

RS384

RSASSA-PKCS-v1_5 using SHA-384

RS512

RSASSA-PKCS-v1_5 using SHA-512

ES256

ECDSA using P-256 and SHA-256

ES384

ECDSA using P-384 and SHA-384

ES512

ECDSA using P-521 and SHA-512

PS256

RSASSA-PSS using SHA-256 and MGF1 with SHA-256

PS384

RSASSA-PSS using SHA-384 and MGF1 with SHA-384

PS512

RSASSA-PSS using SHA-512 and MGF1 with SHA-512

none

No digital signature or MAC performed

Arguments:

Result:

Possible exceptions

  • NullPointerException - throws if the payload, term, secret or signatureAlgorithm argument is NULL

  • SignatureException - throws if the unsupported signature algorithm was defined


getTokenPayload

Returns the payload as a JSON object from the serialized jwt token.

Arguments:

Result:

Possible exceptions


isSignatureValid

Is used to verify the integrity and authenticity of a JSON Web Token (JWT). It checks whether the signature of the token is valid by comparing it against the provided secret. This function is crucial for ensuring that the token has not been tampered with and that it was indeed issued by a trusted party.

Arguments:

Result:

Possible exceptions

Last updated