Class RawJwt.Builder

  • Enclosing class:
    RawJwt

    public static final class RawJwt.Builder
    extends java.lang.Object
    Builder for RawJwt
    • Method Detail

      • setTypeHeader

        @CanIgnoreReturnValue
        public RawJwt.Builder setTypeHeader​(java.lang.String value)
        Sets the Type Header Parameter.

        When set, this value should be set to a shortended IANA MediaType, see https://tools.ietf.org/html/rfc7519#section-5.1 and https://tools.ietf.org/html/rfc8725#section-3.11

      • setIssuer

        @CanIgnoreReturnValue
        public RawJwt.Builder setIssuer​(java.lang.String value)
        Sets the issuer claim that identifies the principal that issued the JWT.

        https://tools.ietf.org/html/rfc7519#section-4.1.1

      • setSubject

        @CanIgnoreReturnValue
        public RawJwt.Builder setSubject​(java.lang.String value)
        Sets the subject claim identifying the principal that is the subject of the JWT.

        https://tools.ietf.org/html/rfc7519#section-4.1.2

      • setAudience

        @CanIgnoreReturnValue
        public RawJwt.Builder setAudience​(java.lang.String value)
        Sets the audience that the JWT is intended for.

        Sets the aud claim as a string. This method can't be used together with setAudiences or addAudience.

        https://tools.ietf.org/html/rfc7519#section-4.1.3

      • setAudiences

        @CanIgnoreReturnValue
        public RawJwt.Builder setAudiences​(java.util.List<java.lang.String> values)
        Sets the audiences that the JWT is intended for.

        Sets the aud claim as an array of strings. This method can't be used together with setAudience.

        https://tools.ietf.org/html/rfc7519#section-4.1.3

      • addAudience

        @CanIgnoreReturnValue
        public RawJwt.Builder addAudience​(java.lang.String value)
        Adds an audience that the JWT is intended for.

        The aud claim will always be encoded as an array of strings. This method can't be used together with setAudience.

        https://tools.ietf.org/html/rfc7519#section-4.1.3

      • setJwtId

        @CanIgnoreReturnValue
        public RawJwt.Builder setJwtId​(java.lang.String value)
        Sets the JWT ID claim that provides a unique identifier for the JWT.

        https://tools.ietf.org/html/rfc7519#section-4.1.7

      • setExpiration

        @CanIgnoreReturnValue
        public RawJwt.Builder setExpiration​(java.time.Instant value)
        Sets the exp claim that identifies the instant on or after which the token MUST NOT be accepted for processing.

        This API requires Instant which is unavailable on Android until API level 26. To use it on older Android devices, enable API desugaring as shown in https://developer.android.com/studio/write/java8-support#library-desugaring.

        https://tools.ietf.org/html/rfc7519#section-4.1.4

      • withoutExpiration

        @CanIgnoreReturnValue
        public RawJwt.Builder withoutExpiration()
        Allow generating tokens without an expiration.

        For most applications of JWT, an expiration date should be set. This function makes sure that this is not forgotten, by requiring to user to explicitly state that no expiration should be set.

      • setNotBefore

        @CanIgnoreReturnValue
        public RawJwt.Builder setNotBefore​(java.time.Instant value)
        Sets the nbf claim that identifies the instant before which the token MUST NOT be accepted for processing.

        This API requires Instant which is unavailable on Android until API level 26. To use it on older Android devices, enable API desugaring as shown in https://developer.android.com/studio/write/java8-support#library-desugaring.

        https://tools.ietf.org/html/rfc7519#section-4.1.5

      • setIssuedAt

        @CanIgnoreReturnValue
        public RawJwt.Builder setIssuedAt​(java.time.Instant value)
        Sets the iat claim that identifies the instant at which the JWT was issued.

        This API requires Instant which is unavailable on Android until API level 26. To use it on older Android devices, enable API desugaring as shown in https://developer.android.com/studio/write/java8-support#library-desugaring.

        https://tools.ietf.org/html/rfc7519#section-4.1.6

      • addBooleanClaim

        @CanIgnoreReturnValue
        public RawJwt.Builder addBooleanClaim​(java.lang.String name,
                                              boolean value)
        Adds a custom claim of type boolean to the JWT.
      • addNumberClaim

        @CanIgnoreReturnValue
        public RawJwt.Builder addNumberClaim​(java.lang.String name,
                                             long value)
        Adds a custom claim of type long to the JWT.
      • addNumberClaim

        @CanIgnoreReturnValue
        public RawJwt.Builder addNumberClaim​(java.lang.String name,
                                             double value)
        Adds a custom claim of type double to the JWT.
      • addStringClaim

        @CanIgnoreReturnValue
        public RawJwt.Builder addStringClaim​(java.lang.String name,
                                             java.lang.String value)
        Adds a custom claim of type String to the JWT.
      • addNullClaim

        @CanIgnoreReturnValue
        public RawJwt.Builder addNullClaim​(java.lang.String name)
        Adds a custom claim with value null.
      • addJsonObjectClaim

        @CanIgnoreReturnValue
        public RawJwt.Builder addJsonObjectClaim​(java.lang.String name,
                                                 java.lang.String encodedJsonObject)
                                          throws JwtInvalidException
        Adds a custom claim encoded in a JSON String to the JWT.
        Throws:
        JwtInvalidException
      • build

        public RawJwt build()