Class JWT

java.lang.Object
io.fusionauth.jwt.domain.JWT

public class JWT extends Object
JSON Web Token (JWT) as defined by RFC 7519.
 From RFC 7519 Section 1. Introduction:
    The suggested pronunciation of JWT is the same as the English word "jot".
 
The JWT is not Thread-Safe and should not be re-used.
Author:
Daniel DeGroff
  • Field Details

    • audience

      public Object audience
      Registered Claim aud as defined by RFC 7519 Section 4.1.3. Use of this claim is OPTIONAL.

      The audience claim identifies the recipients that the JWT is intended for. This may be an array of strings or a single string, in either case if the string value contains a : it must be a URI.

    • expiration

      public java.time.ZonedDateTime expiration
      Registered Claim exp as defined by RFC 7519 Section 4.1.4. Use of this claim is OPTIONAL.

      The expiration time claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. The expiration time is expected to provided in UNIX time, or the number of seconds since Epoch.

    • issuedAt

      public java.time.ZonedDateTime issuedAt
      Registered Claim iat as defined by RFC 7519 Section 4.1.6. Use of this claim is OPTIONAL.

      The issued at claim identifies the time at which the JWT was issued. The issued at time is expected to provided in UNIX time, or the number of seconds since Epoch.

    • issuer

      public String issuer
      Registered Claim iss as defined by RFC 7519 Section 4.1.1. Use of this claim is OPTIONAL.

      The issuer claim identifies the principal that issued the JWT. If the value contains a : it must be a URI.

    • notBefore

      public java.time.ZonedDateTime notBefore
      Registered Claim nbf as defined by RFC 7519 Section 4.1.5. Use of this claim is OPTIONAL.

      This claim identifies the time before which the JWT MUST NOT be accepted for processing. The not before value is expected to be provided in UNIX time, or the number of seconds since Epoch.

    • otherClaims

      public Map<String,Object> otherClaims
      This Map will contain all the claims that aren't specifically defined in the specification. These still might be IANA registered claims, but are not known JWT specification claims.
    • subject

      public String subject
      Registered Claim sub as defined by RFC 7519 Section 4.1.2. Use of this claim is OPTIONAL.

      The subject claim identifies the principal that is the subject of the JWT. If the value contains a : it must be a URI.

    • uniqueId

      public String uniqueId
      Registered Claim jti as defined by RFC 7519 Section 4.1.7. Use of this claim is OPTIONAL.

      The JWT unique ID claim provides a unique identifier for the JWT.

  • Constructor Details

    • JWT

      public JWT()
  • Method Details

    • getDecoder

      public static JWTDecoder getDecoder()
      Return an instance of the JWT Decoder.
      Returns:
      a JWT decoder.
    • getTimeMachineDecoder

      public static JWTDecoder getTimeMachineDecoder(java.time.ZonedDateTime now)
      Return a JWT Decoder that allows you to go back or of forward in time. Use this at your own risk.

      Generally speaking, there should not be a use for this in production code since 'now' should always be 'now', but it may come in handy in a test.

      Parameters:
      now - a 'now' that can be in the past, present or future.
      Returns:
      a JWT decoder with time machine capability.
    • getEncoder

      public static JWTEncoder getEncoder()
      Return an instance of the JWT encoder.
      Returns:
      a JWT encoder.
    • getHeaderClaim

      public Object getHeaderClaim(String name)
    • addClaim

      public JWT addClaim(String name, Object value)
      Add a claim to this JWT. This claim can be public or private, it is up to the caller to properly name the claim as to avoid collision.
      Parameters:
      name - The name of the JWT claim.
      value - The value of the JWT claim. This value is an object and is expected to properly serialize.
      Returns:
      this.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • getAllClaims

      public Map<String,Object> getAllClaims()
      Returns:
      Returns all the claims as cool Java types like ZonedDateTime (where appropriate of course). This will contain the otherClaims and the known JWT claims.
    • getBigDecimal

      public BigDecimal getBigDecimal(String key)
    • getBigInteger

      public BigInteger getBigInteger(String key)
    • getBoolean

      public Boolean getBoolean(String key)
    • getDouble

      public Double getDouble(String key)
    • getFloat

      public Float getFloat(String key)
    • getInteger

      public Integer getInteger(String key)
    • getList

      public List<Object> getList(String key)
    • getLong

      public Long getLong(String key)
    • getMap

      public Map<String,Object> getMap(String key)
    • getNumber

      public Number getNumber(String key)
    • getObject

      public Object getObject(String key)
    • getOtherClaims

      public Map<String,Object> getOtherClaims()
    • getRawClaims

      public Map<String,Object> getRawClaims()
      Returns:
      Returns the original claims from the JWT without any Java data types like ZonedDateTime. This will contain the otherClaims and the known JWT claims.
    • getString

      public String getString(String key)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isExpired

      public boolean isExpired()
      Return true if this JWT is expired.
      Returns:
      true if expired, false if not.
    • isExpired

      public boolean isExpired(java.time.ZonedDateTime now)
      Return true if this JWT is expired.
      Parameters:
      now - the 'now' you wish to use.
      Returns:
      true if expired, false if not.
    • isUnavailableForProcessing

      public boolean isUnavailableForProcessing(java.time.ZonedDateTime now)
      Return true if this JWT is un-available for processing.
      Parameters:
      now - the 'now' you wish to use.
      Returns:
      true if un-available, false if not.
    • isUnavailableForProcessing

      public boolean isUnavailableForProcessing()
      Return true if this JWT is un-available for processing.
      Returns:
      true if un-available, false if not.
    • setAudience

      public JWT setAudience(Object audience)
    • setExpiration

      public JWT setExpiration(java.time.ZonedDateTime expiration)
    • setIssuedAt

      public JWT setIssuedAt(java.time.ZonedDateTime issuedAt)
    • setIssuer

      public JWT setIssuer(String issuer)
    • setNotBefore

      public JWT setNotBefore(java.time.ZonedDateTime notBefore)
    • setSubject

      public JWT setSubject(String subject)
    • setUniqueId

      public JWT setUniqueId(String uniqueId)
    • toString

      public String toString()
      Overrides:
      toString in class Object