Class JWT


  • public class JWT
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      JWT()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String generate​(java.lang.String secretKey, java.lang.String algo, java.lang.String data, java.lang.String issuer, java.lang.String audience, java.lang.String subject, java.lang.String jwtid, long expiresInSeconds)
      Generate JWT (token) with the given configuration.
      static java.lang.String generate​(java.lang.String secretKey, java.lang.String algo, org.json.JSONObject data, java.lang.String issuer, java.lang.String audience, java.lang.String subject, java.lang.String jwtid, long expiresInSeconds)
      Generate JWT (token) with the given configuration.
      static java.util.Map<java.lang.String,​com.auth0.jwt.interfaces.Claim> parse​(java.lang.String token, java.lang.String secretKey, java.lang.String algo)
      Validates and parses a JWT (token).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JWT

        public JWT()
    • Method Detail

      • generate

        public static java.lang.String generate​(java.lang.String secretKey,
                                                java.lang.String algo,
                                                java.lang.String data,
                                                java.lang.String issuer,
                                                java.lang.String audience,
                                                java.lang.String subject,
                                                java.lang.String jwtid,
                                                long expiresInSeconds)
        Generate JWT (token) with the given configuration. Using java-jwt library (https://github.com/auth0/java-jwt)
        Parameters:
        secretKey - The secure key used to encrypt the payload (if an encryption algorithm is selected)
        algo - The encryption algorithm to use (defaults to NONE). Currently supported: HS256, HS384, HS512, NONE
        data - The additional claim (key-value pairs) as serialized JSON object (String).
        issuer - The token issuer
        audience - The intended audience of the token
        subject - An optional subject for the token
        jwtid - An optional JWT-ID
        expiresInSeconds - Number of seconds after which the token expires
        Returns:
        The generated token
        Throws:
        java.lang.IllegalArgumentException - if `data` is not a valid JSON Object
      • generate

        public static java.lang.String generate​(java.lang.String secretKey,
                                                java.lang.String algo,
                                                org.json.JSONObject data,
                                                java.lang.String issuer,
                                                java.lang.String audience,
                                                java.lang.String subject,
                                                java.lang.String jwtid,
                                                long expiresInSeconds)
        Generate JWT (token) with the given configuration. Using java-jwt library (https://github.com/auth0/java-jwt)
        Parameters:
        secretKey - The secure key used to encrypt the payload (if an encryption algorithm is selected)
        algo - The encryption algorithm to use (defaults to NONE). Currently supported: HMAC256, HMAC384, HMAC512, NONE
        data - The JSONObject with key-value pairs of the additional claim/data.
        issuer - The token issuer
        audience - The intended audience of the token
        subject - An optional subject for the token
        jwtid - An optional JWT-ID
        expiresInSeconds - Number of seconds after which the token expires
        Returns:
        The generated token
      • parse

        public static java.util.Map<java.lang.String,​com.auth0.jwt.interfaces.Claim> parse​(java.lang.String token,
                                                                                                 java.lang.String secretKey,
                                                                                                 java.lang.String algo)
                                                                                          throws com.auth0.jwt.exceptions.JWTVerificationException
        Validates and parses a JWT (token). If valid, returns a Map of key-value pairs of the claims.
        Parameters:
        token - The JWT to parse.
        secretKey - The secure key that was used to encrypt the token
        algo - The encryption algorithm used to generate the token
        Returns:
        The Map of claim (payload) key-value pairs.
        Throws:
        com.auth0.jwt.exceptions.JWTVerificationException - if the token cannot be verified