Package com.auth0.jwt

Class JWTVerifier.BaseVerification

  • All Implemented Interfaces:
    Verification
    Enclosing class:
    JWTVerifier

    public static class JWTVerifier.BaseVerification
    extends Object
    implements Verification
    The Verification class holds the Claims required by a JWT to be valid.
    • Method Detail

      • withIssuer

        public Verification withIssuer​(String... issuer)
        Require a specific Issuer ("iss") claim.
        Specified by:
        withIssuer in interface Verification
        Parameters:
        issuer - the required Issuer value. If multiple values are given, the claim must at least match one of them
        Returns:
        this same Verification instance.
      • withSubject

        public Verification withSubject​(String subject)
        Require a specific Subject ("sub") claim.
        Specified by:
        withSubject in interface Verification
        Parameters:
        subject - the required Subject value
        Returns:
        this same Verification instance.
      • withAudience

        public Verification withAudience​(String... audience)
        Require a specific Audience ("aud") claim.
        Specified by:
        withAudience in interface Verification
        Parameters:
        audience - the required Audience value
        Returns:
        this same Verification instance.
      • acceptLeeway

        public Verification acceptLeeway​(long leeway)
                                  throws IllegalArgumentException
        Define the default window in seconds in which the Not Before, Issued At and Expires At Claims will still be valid. Setting a specific leeway value on a given Claim will override this value for that Claim.
        Specified by:
        acceptLeeway in interface Verification
        Parameters:
        leeway - the window in seconds in which the Not Before, Issued At and Expires At Claims will still be valid.
        Returns:
        this same Verification instance.
        Throws:
        IllegalArgumentException - if leeway is negative.
      • acceptExpiresAt

        public Verification acceptExpiresAt​(long leeway)
                                     throws IllegalArgumentException
        Set a specific leeway window in seconds in which the Expires At ("exp") Claim will still be valid. Expiration Date is always verified when the value is present. This method overrides the value set with acceptLeeway
        Specified by:
        acceptExpiresAt in interface Verification
        Parameters:
        leeway - the window in seconds in which the Expires At Claim will still be valid.
        Returns:
        this same Verification instance.
        Throws:
        IllegalArgumentException - if leeway is negative.
      • acceptNotBefore

        public Verification acceptNotBefore​(long leeway)
                                     throws IllegalArgumentException
        Set a specific leeway window in seconds in which the Not Before ("nbf") Claim will still be valid. Not Before Date is always verified when the value is present. This method overrides the value set with acceptLeeway
        Specified by:
        acceptNotBefore in interface Verification
        Parameters:
        leeway - the window in seconds in which the Not Before Claim will still be valid.
        Returns:
        this same Verification instance.
        Throws:
        IllegalArgumentException - if leeway is negative.
      • acceptIssuedAt

        public Verification acceptIssuedAt​(long leeway)
                                    throws IllegalArgumentException
        Set a specific leeway window in seconds in which the Issued At ("iat") Claim will still be valid. Issued At Date is always verified when the value is present. This method overrides the value set with acceptLeeway
        Specified by:
        acceptIssuedAt in interface Verification
        Parameters:
        leeway - the window in seconds in which the Issued At Claim will still be valid.
        Returns:
        this same Verification instance.
        Throws:
        IllegalArgumentException - if leeway is negative.
      • ignoreIssuedAt

        public Verification ignoreIssuedAt()
        Skip the Issued At ("iat") date verification. By default, the verification is performed.
        Specified by:
        ignoreIssuedAt in interface Verification
      • withJWTId

        public Verification withJWTId​(String jwtId)
        Require a specific JWT Id ("jti") claim.
        Specified by:
        withJWTId in interface Verification
        Parameters:
        jwtId - the required Id value
        Returns:
        this same Verification instance.
      • build

        public JWTVerifier build()
        Creates a new and reusable instance of the JWTVerifier with the configuration already provided.
        Specified by:
        build in interface Verification
        Returns:
        a new JWTVerifier instance.
      • build

        public JWTVerifier build​(Clock clock)
        Creates a new and reusable instance of the JWTVerifier with the configuration already provided. ONLY FOR TEST PURPOSES.
        Parameters:
        clock - the instance that will handle the current time.
        Returns:
        a new JWTVerifier instance with a custom Clock.