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.
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.
-
Makes a duplicate copy of the JWT object.
-
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.
-
Returns the audience (
aud) claim that identifies the intended recipients of the JWT. -
Returns the issuer (
iss) claim that identifies the issuer of the JWT. -
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 aNoAccessexception for JWTs generated using methods in theAuth.JWTUtilclass. To return thenbfclaim for these JWTs, use thegetAdditionalClaimsmethod instead. -
Returns the subject (
sub) claim that identifies the current user of the JWT. -
Returns the length of time (in seconds) that the JWT is valid, which affects the expiration (
exp) claim. This method returns aNoAccessexception for JWTs generated using methods in theAuth.JWTUtilclass. To return the validity length for these JWTs, use thegetAdditionalClaimsmethod instead. -
setAdditionalClaims(additionalClaims)
Sets the additional claims in the JWT. Returned by the
getAdditionalClaimsmethod. -
Sets the audience (
aud) claim in the JWT. Returned by thegetAudmethod. -
Sets the issuer (
iss) claim in the JWT. Returned by thegetIssmethod. -
Sets the not before (
nbf) claim in the JWT. Returned by thegetNbfClockSkewmethod. This method returns aNoAccessexception for JWTs generated using methods in theAuth.JWTUtilclass. For these JWTs, the incoming JWT determines thenbfclaim. -
Sets the subject (
sub) claim in the JWT. Returned by thegetSubmethod. -
setValidityLength(validityLength)
Sets the length of time (in seconds) that the JWT is valid, which affects the expiration (
exp) claim. Returned by thegetValidityLengthmethod. This method returns aNoAccessexception for JWTs generated using methods in theAuth.JWTUtilclass. For these JWTs, the incoming JWT determines the validity length. -
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()
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 thegetAudmethod instead.iss(issuer)—Use thegetIssmethod instead.sub(subject)—Use thegetSubmethod 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)
-
aud:
Type: String
Type: void
Sets the issuer (iss) claim in the JWT. Returned by the getIss method.
public void setIss(String iss)
-
iss:
Type: String
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)
-
nbfClockSkew:
Type: Integer
Type: void
Sets the subject (sub) claim in the JWT. Returned by the getSub method.
public void setSub(String sub)
-
sub:
Type: String
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)
-
validityLength:
Type: Integer
Type: void
Generates the JSON object representation of the Claims Set as an encoded JWT payload.
public String toJSONString()
Type: String