java.lang.Object
uk.co.spudsoft.jwtvalidatorvertx.JWT

public class JWT extends Object
A JWT as defined by RFC7519. The internal representation is two JSON objects, the signature (as string) and the original string that was used to generate the signature (concatenated base 64 header and payload). Values are not extracted or cached, they are simply retrieved on demand.
Author:
jtalbut
  • Constructor Details

    • JWT

      public JWT(io.vertx.core.json.JsonObject header, io.vertx.core.json.JsonObject payload, String signatureBase, String signature)
      Constructor.
      Parameters:
      header - The header from the JWT.
      payload - The payload from the JWT.
      signatureBase - The value used to calculate the signature - base64(header) + "." + base64(payload).
      signature - The signature from the JWT.
  • Method Details

    • parseJws

      public static JWT parseJws(String token)
      Parse a JWT in delimited string form.
      Parameters:
      token - The JWT in delimited string form.
      Returns:
      A newly created JWT object.
    • getPayloadSize

      public int getPayloadSize()
      Get the number of claims in the payload.
      Returns:
      the number of claims in the payload.
    • getClaim

      public Object getClaim(String claim)
      Get a single payload claim by name.
      Parameters:
      claim - The name of the claim to return.
      Returns:
      the claim with the given name.
    • getClaimAsList

      public List<String> getClaimAsList(String claim)
      Get a payload claim by name returning a List or Strings.
      Parameters:
      claim - The name of the claim to return.
      Returns:
      the claim with the given name, as a List of Strings.
    • getSignatureBase

      public String getSignatureBase()
      Get the value used to calculate the signature - base64(header) + "." + base64(payload).
      Returns:
      the value used to calculate the signature - base64(header) + "." + base64(payload).
    • getSignature

      public String getSignature()
      Get the signature from the JWT.
      Returns:
      the signature from the JWT.
    • getAlgorithm

      public String getAlgorithm()
      Get the algorithm specified in the JWT header.
      Returns:
      the algorithm specified in the JWT header.
    • getJsonWebAlgorithm

      public JsonWebAlgorithm getJsonWebAlgorithm()
      Get the algorithm specified in the JWT header as a JsonWebAlgorithm.
      Returns:
      the algorithm specified in the JWT header as a JsonWebAlgorithm.
    • getKid

      public String getKid()
      Get the key ID specified in the JWT header.
      Returns:
      the key ID specified in the JWT header.
    • getSubject

      public String getSubject()
      Get the token subject specified in the JWT payload.
      Returns:
      the token subject specified in the JWT payload.
    • getIssuer

      public String getIssuer()
      Get the token issuer specified in the JWT payload.
      Returns:
      the token issuer specified in the JWT payload.
    • getAudience

      public List<String> getAudience()
      Get the token audience specified in the JWT payload. The audience can be specified as either a single value or a JSON array, this method normalizes the result to an array of strings.
      Returns:
      the token audience specified in the JWT payload.
    • getScope

      public List<String> getScope()
      Get the scopes specified in the JWT payload. Note that this method parses the scope string into separate scopes.
      Returns:
      the scopes specified in the JWT payload.
    • getGroups

      public List<String> getGroups()
      Get the groups specified in the JWT payload.
      Returns:
      the groups specified in the JWT payload.
    • getRoles

      public List<String> getRoles()
      Get the roles specified in the JWT payload.
      Returns:
      the roles specified in the JWT payload.
    • getExpiration

      public Long getExpiration()
      Get the expiration timestamp specified in the JWT payload. The expiration timestamp is defined as seconds since epoch (1970-01-01T00:00:00Z UTC), see RFC 7519 Section 4.1.4 and Section 2.
      Returns:
      the expiration timestamp specified in the JWT payload.
    • getExpirationLocalDateTime

      public LocalDateTime getExpirationLocalDateTime()
      Get the expiration timestamp specified in the JWT payload as a LocalDateTime.
      Returns:
      the expiration timestamp specified in the JWT payload as a LocalDateTime.
    • getNotBefore

      public Long getNotBefore()
      Get the not-valid-before timestamp specified in the JWT payload. The not-valid-before timestamp is defined as seconds since epoch (1970-01-01T00:00:00Z UTC), see RFC 7519 Section 4.1.5 and Section 2.
      Returns:
      the not-valid-before timestamp specified in the JWT payload.
    • getNotBeforeLocalDateTime

      public LocalDateTime getNotBeforeLocalDateTime()
      Get the not-valid-before timestamp specified in the JWT payload as a LocalDateTime.
      Returns:
      the not-valid-before timestamp specified in the JWT payload as a LocalDateTime.
    • getJwk

      public io.vertx.core.Future<JWK> getJwk(JsonWebKeySetHandler handler)
      Use the provided OpenIdDiscoveryHandler to call the jwks_uri from the discovery data to obtain the correct JWK for this JWT. The JWK will be cached in this JWT after it has been retrieved (and this method will return immediately if called again).
      Parameters:
      handler - the OpenIdDiscoveryHandler that will perform the request for the JWK Set.
      Returns:
      A Future that will be completed with a JWK object when the discovery completes.
    • getJwk

      public JWK getJwk()
      Get the jwk cached by a successful call to getJwk(uk.co.spudsoft.jwtvalidatorvertx.JsonWebKeySetHandler). This method should only be called in a handler chain following a successful called to getJwk(uk.co.spudsoft.jwtvalidatorvertx.JsonWebKeySetHandler).
      Returns:
      the jwk cached by a successful called to getJwk(uk.co.spudsoft.jwtvalidatorvertx.JsonWebKeySetHandler).