Class Jwt.Builder

java.lang.Object
com.vonage.jwt.Jwt.Builder
Enclosing class:
Jwt

public static class Jwt.Builder extends Object
Builder for setting the properties of a JWT.
  • Constructor Details

  • Method Details

    • applicationId

      public Jwt.Builder applicationId(UUID applicationId)
      (REQUIRED) Sets the application ID. This must be your Vonage application ID.
      Parameters:
      applicationId - The application UUID.
      Returns:
      This builder.
    • applicationId

      public Jwt.Builder applicationId(String 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

      public Jwt.Builder privateKeyContents(String privateKeyContents)
      (CONDITIONAL) Sets the private key used for signing the JWT.
      Parameters:
      privateKeyContents - The actual private key as a string.
      Returns:
      This builder.
    • privateKeyPath

      public Jwt.Builder privateKeyPath(Path privateKeyPath) throws IOException
      (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

      public Jwt.Builder privateKeyPath(String privateKeyPath) throws IOException
      (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

      public Jwt.Builder withProperties(Consumer<com.auth0.jwt.JWTCreator.Builder> jwtBuilder)
      (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

      public Jwt.Builder claims(Map<String,?> 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

      public Jwt.Builder addClaim(String key, Object value)
      (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 the iat claim. 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

      public Jwt.Builder id(String jti)
      (OPTIONAL) Sets the jti claim. 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 the nbf claim.
      Parameters:
      nbf - The start time at which the generated JWTs will be valid from.
      Returns:
      This builder.
    • expiresAt

      (OPTIONAL) Sets the exp claim.
      Parameters:
      exp - The expiry time of generated JWTs.
      Returns:
      This builder.
    • subject

      public Jwt.Builder subject(String sub)
      (OPTIONAL) Sets the sub claim.
      Parameters:
      sub - The subject of generated JWTs.
      Returns:
      This builder.
    • build

      public Jwt 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.