Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This script generates a JWT and prints it out. Replace "your-256-bit-secret" with a proper secret key.

Note: for the expiration time

$ ([DateTime]('1970,1,1')).AddSeconds(3000000000)
24 January 2065 05:20:00

Sending the JWT in a REST Request Header

...

Code Block
languagejava
themeMidnight
import java.util.Base64;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import java.io.StringReader;

public class ParseJWT {
 

    public static void mainparseClientId(String[] argstoken) {
        // Assume token is passed or retrieved from headers
 
      String token = "your.jwt.token.here";
        
        // Split token into its parts
        String[] chunks = token.split("\\.");
        Base64.Decoder decoder = Base64.getUrlDecoder();
        
        // Decode payload
        String payload = new String(decoder.decode(chunks[1]));
        
        // Parse JSON
        JsonReader jsonReader = Json.createReader(new StringReader(payload));
        JsonObject jsonObject = jsonReader.readObject();
        jsonReader.close();
        
        // Extract the client_id
        String clientId = jsonObject.getString("client_id");
        System.out.println("Client ID: " + clientId);
        return clientId;
    }
}


In the create policy code check if there is an header and if there is a clientId use it as serviceId, other cases are covered having default serviceId (If there is no header, if there is an header but not a clientId)

...