Class JwtClaims

java.lang.Object
com.google.auth.oauth2.JwtClaims
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AutoValue_JwtClaims

public abstract class JwtClaims extends Object implements Serializable
Value class representing the set of fields used as the payload of a JWT token.

To create and customize claims, use the builder:


 Claims claims = Claims.newBuilder()
     .setAudience("https://example.com/some-audience")
     .setIssuer("some-issuer@example.com")
     .setSubject("some-subject@example.com")
     .build();
 
See Also:
  • Field Details

  • Constructor Details

    • JwtClaims

      public JwtClaims()
  • Method Details

    • getAudience

      @Nullable abstract String getAudience()
    • getIssuer

      @Nullable abstract String getIssuer()
    • getSubject

      @Nullable abstract String getSubject()
    • getAdditionalClaims

      abstract Map<String,String> getAdditionalClaims()
      Returns additional claims for this object. The returned map is not guaranteed to be mutable.
      Returns:
      additional claims
    • newBuilder

      public static JwtClaims.Builder newBuilder()
    • merge

      public JwtClaims merge(JwtClaims other)
      Returns a new Claims instance with overridden fields.

      Any non-null field will overwrite the value from the original claims instance.

      Parameters:
      other - claims to override
      Returns:
      new claims
    • isComplete

      public boolean isComplete()
      Returns whether or not this set of claims is complete.

      Audience, issuer, and subject are required to be set in order to use the claim set for a JWT token. An incomplete Claims instance is useful for overriding claims when using ServiceAccountJwtAccessCredentials.jwtWithClaims(JwtClaims) or JwtCredentials.jwtWithClaims(JwtClaims).

      Returns:
      true if all required fields have been set; false otherwise