JWT Class

Generates the JSON Claims Set in a JSON Web Token (JWT). The resulting Base64-encoded payload can be passed as an argument to create an instance of the Auth.JWS class.

Auth

Use the methods in this class to generate the payload in a JWT bearer token for the OAuth 2.0 JWT bearer token flow. For more information and a full code sample, see JWTBearerTokenExchange Class.

The following are methods for JWT. All are instance methods.

  • clone()

    Makes a duplicate copy of the JWT object.

  • getAdditionalClaims()

    Returns a map of additional claims in the JWT, where the key string contains the name of the claim, and the value contains the value of the claim.

  • getAud()

    Returns the audience (aud) claim that identifies the intended recipients of the JWT.

  • getIss()

    Returns the issuer (iss) claim that identifies the issuer of the JWT.

  • getNbfClockSkew()

    Returns the not before (nbf) claim that identifies the time before which the JWT must not be accepted for processing, while allowing some leeway for clock skew. This method returns a NoAccess exception for JWTs generated using methods in the Auth.JWTUtil class. To return the nbf claim for these JWTs, use the getAdditionalClaims method instead.

  • getSub()

    Returns the subject (sub) claim that identifies the current user of the JWT.

  • getValidityLength()

    Returns the length of time (in seconds) that the JWT is valid, which affects the expiration (exp) claim. This method returns a NoAccess exception for JWTs generated using methods in the Auth.JWTUtil class. To return the validity length for these JWTs, use the getAdditionalClaims method instead.

  • setAdditionalClaims(additionalClaims)

    Sets the additional claims in the JWT. Returned by the getAdditionalClaims method.

  • setAud(aud)

    Sets the audience (aud) claim in the JWT. Returned by the getAud method.

  • setIss(iss)

    Sets the issuer (iss) claim in the JWT. Returned by the getIss method.

  • setNbfClockSkew(nbfClockSkew)

    Sets the not before (nbf) claim in the JWT. Returned by the getNbfClockSkew method. This method returns a NoAccess exception for JWTs generated using methods in the Auth.JWTUtil class. For these JWTs, the incoming JWT determines the nbf claim.

  • setSub(sub)

    Sets the subject (sub) claim in the JWT. Returned by the getSub method.

  • setValidityLength(validityLength)

    Sets the length of time (in seconds) that the JWT is valid, which affects the expiration (exp) claim. Returned by the getValidityLength method. This method returns a NoAccess exception for JWTs generated using methods in the Auth.JWTUtil class. For these JWTs, the incoming JWT determines the validity length.

  • toJSONString()

    Generates the JSON object representation of the Claims Set as an encoded JWT payload.

Makes a duplicate copy of the JWT object.

public Object clone()

Type: JWT

Returns a map of additional claims in the JWT, where the key string contains the name of the claim, and the value contains the value of the claim.

public Map<String,Object> getAdditionalClaims()

Type: Map<String,Object>

The claims returned depend on how the JWT was generated.

If the JWT was generated using other methods in the Auth.JWT class, this method returns the claims that were set using the setAdditionalClaims method.

For JWTs generated using methods in the Auth.JWTUtil class, the getAdditionalClaims method returns all claims except for these three.

  • aud (audience)—Use the getAud method instead.
  • iss (issuer)—Use the getIss method instead.
  • sub (subject)—Use the getSub method instead.

For these JWTs, when the incoming JWT has a claim that stores an inner JSON list, the claim value is returned as a string.

Returns the audience (aud) claim that identifies the intended recipients of the JWT.

public String getAud()

Type: String

Returns the issuer (iss) claim that identifies the issuer of the JWT.

public String getIss()

Type: String

Returns the not before (nbf) claim that identifies the time before which the JWT must not be accepted for processing, while allowing some leeway for clock skew. This method returns a NoAccess exception for JWTs generated using methods in the Auth.JWTUtil class. To return the nbf claim for these JWTs, use the getAdditionalClaims method instead.

public Integer getNbfClockSkew()

Type: Integer

Returns the subject (sub) claim that identifies the current user of the JWT.

public String getSub()

Type: String

Returns the length of time (in seconds) that the JWT is valid, which affects the expiration (exp) claim. This method returns a NoAccess exception for JWTs generated using methods in the Auth.JWTUtil class. To return the validity length for these JWTs, use the getAdditionalClaims method instead.

public Integer getValidityLength()

Type: Integer

Sets the additional claims in the JWT. Returned by the getAdditionalClaims method.

public void setAdditionalClaims(Map<String,Object> additionalClaims)

Type: void

Additional claims must not include any standard claims.

Sets the audience (aud) claim in the JWT. Returned by the getAud method.

public void setAud(String aud)

Type: void

Sets the issuer (iss) claim in the JWT. Returned by the getIss method.

public void setIss(String iss)

Type: void

Sets the not before (nbf) claim in the JWT. Returned by the getNbfClockSkew method. This method returns a NoAccess exception for JWTs generated using methods in the Auth.JWTUtil class. For these JWTs, the incoming JWT determines the nbf claim.

public void setNbfClockSkew(Integer nbfClockSkew)

Type: void

Sets the subject (sub) claim in the JWT. Returned by the getSub method.

public void setSub(String sub)

Type: void

Sets the length of time (in seconds) that the JWT is valid, which affects the expiration (exp) claim. Returned by the getValidityLength method. This method returns a NoAccess exception for JWTs generated using methods in the Auth.JWTUtil class. For these JWTs, the incoming JWT determines the validity length.

public void setValidityLength(Integer validityLength)

Type: void

Generates the JSON object representation of the Claims Set as an encoded JWT payload.

public String toJSONString()

Type: String