Package com.vonage.jwt
Class Jwt.Builder
java.lang.Object
com.vonage.jwt.Jwt.Builder
- Enclosing class:
- Jwt
Builder for setting the properties of a JWT.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(OPTIONAL) Adds a custom claim for generated JWTs.applicationId(String applicationId) (REQUIRED) Sets the application ID.applicationId(UUID applicationId) (REQUIRED) Sets the application ID.build()Builds the JWT generator using this builder's settings.(OPTIONAL) Sets additional custom claims of the generated JWTs.expiresAt(ZonedDateTime exp) (OPTIONAL) Sets theexpclaim.(OPTIONAL) Sets thejticlaim.issuedAt(ZonedDateTime iat) (OPTIONAL) Sets theiatclaim.notBefore(ZonedDateTime nbf) (OPTIONAL) Sets thenbfclaim.privateKeyContents(String privateKeyContents) (CONDITIONAL) Sets the private key used for signing the JWT.privateKeyPath(String privateKeyPath) (CONDITIONAL) Sets the private key by reading it from a file.privateKeyPath(Path privateKeyPath) (CONDITIONAL) Sets the private key by reading it from a file.(OPTIONAL) Sets thesubclaim.unsigned()(CONDITIONAL) Create an unsigned token.withProperties(Consumer<com.auth0.jwt.JWTCreator.Builder> jwtBuilder) (OPTIONAL) This method enables specifying claims and other properties using the Auth0 JWT builder.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
applicationId
(REQUIRED) Sets the application ID. This must be your Vonage application ID.- Parameters:
applicationId- The application UUID.- Returns:
- This builder.
-
applicationId
(REQUIRED) Sets the application ID. This must be your Vonage application ID.- Parameters:
applicationId- The application ID as a string. Note that this must be a valid UUID.- Returns:
- This builder.
-
unsigned
(CONDITIONAL) Create an unsigned token. Calling this means you won't need to provide a private key.- Returns:
- This builder.
-
privateKeyContents
(CONDITIONAL) Sets the private key used for signing the JWT.- Parameters:
privateKeyContents- The actual private key as a string.- Returns:
- This builder.
-
privateKeyPath
(CONDITIONAL) Sets the private key by reading it from a file.- Parameters:
privateKeyPath- Absolute path to the private key file.- Returns:
- This builder.
- Throws:
IOException- If the private key couldn't be read from the file.
-
privateKeyPath
(CONDITIONAL) Sets the private key by reading it from a file. This is a convenience method which simply delegates to privateKeyPath(Path).- Parameters:
privateKeyPath- Absolute path to the private key file.- Returns:
- This builder.
- Throws:
IOException- If the private key couldn't be read from the file.
-
withProperties
(OPTIONAL) This method enables specifying claims and other properties using the Auth0 JWT builder.- Parameters:
jwtBuilder- Lambda expression which sets desired properties on the builder.- Returns:
- This builder.
-
claims
(OPTIONAL) Sets additional custom claims of the generated JWTs.- Parameters:
claims- The claims to add as a Map.- Returns:
- This builder.
- See Also:
-
addClaim
(OPTIONAL) Adds a custom claim for generated JWTs.- Parameters:
key- Name of the claim.value- Serializable value of the claim.- Returns:
- This builder.
- See Also:
-
issuedAt
(OPTIONAL) Sets theiatclaim. If unspecified, the current time will be used every time a new JWT is generated.- Parameters:
iat- The issue time of generated JWTs.- Returns:
- This builder.
-
id
(OPTIONAL) Sets thejticlaim. If unspecified, a random UUID will be used every time a new JWT is generated.- Parameters:
jti- The ID (nonce) of the generated JWTs.- Returns:
- This builder.
-
notBefore
(OPTIONAL) Sets thenbfclaim.- Parameters:
nbf- The start time at which the generated JWTs will be valid from.- Returns:
- This builder.
-
expiresAt
(OPTIONAL) Sets theexpclaim.- Parameters:
exp- The expiry time of generated JWTs.- Returns:
- This builder.
-
subject
(OPTIONAL) Sets thesubclaim.- Parameters:
sub- The subject of generated JWTs.- Returns:
- This builder.
-
build
Builds the JWT generator using this builder's settings.- Returns:
- A new JWT generator instance.
- Throws:
IllegalStateException- If the required properties were not set.
-