Package com.vonage.jwt
Class Jwt
java.lang.Object
com.vonage.jwt.Jwt
Class which allows declaratively specifying claims for generating Json Web Tokens (JWTs).
The
builder() static method provides the entry point, from which the mandatory
and optional parameters can be specified. After calling Jwt.Builder.build(), the
options can be re-used to create new tokens using the generate() method.
Signed JWTs can be verified using the static verifySignature(String, String) method.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for setting the properties of a JWT. -
Method Summary
Modifier and TypeMethodDescriptionstatic Jwt.Builderbuilder()Instantiate a new Builder for building Jwt objects.generate()Creates a new Base64-encoded JWT using the settings specified in the builder.Returns theapplication_idclaim.Returns all claims, both standard and non-standard.Returns theexpclaim.getId()Returns thejticlaim.Returns theiatclaim.Returns thenbfclaim.Returns thesubclaim.static booleanverifySignature(String token, String secret) Determines whether the provided JSON Web Token was signed by a given SHA-256 HMAC secret.
-
Method Details
-
generate
Creates a new Base64-encoded JWT using the settings specified in the builder.- Returns:
- A new Json Web Token as a string.
-
getApplicationId
Returns theapplication_idclaim.- Returns:
- The Vonage application UUID.
-
getClaims
Returns all claims, both standard and non-standard.- Returns:
- The claims on this JWT as a Map.
-
getId
Returns thejticlaim.- Returns:
- The JWT ID as a string, or
nullif unspecified.
-
getIssuedAt
Returns theiatclaim.- Returns:
- The issue time as an Instant, or
nullif unspecified.
-
getNotBefore
Returns thenbfclaim.- Returns:
- The start (not before) time as an Instant, or
nullif unspecified.
-
getExpiresAt
Returns theexpclaim.- Returns:
- The expiry time as an Instant, or
nullif unspecified.
-
getSubject
Returns thesubclaim.- Returns:
- The subject, or
nullif unspecified.
-
builder
Instantiate a new Builder for building Jwt objects.- Returns:
- A new Builder.
-
verifySignature
Determines whether the provided JSON Web Token was signed by a given SHA-256 HMAC secret.- Parameters:
secret- The 256-bit symmetric HMAC signature.token- The encoded JWT to check.- Returns:
trueiff the token was signed by the secret,falseotherwise.- Since:
- 1.1.0
-