Versions Compared

Key

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

...

Code Block
languagejava
themeMidnight
import java.util.Base64;
import javaxcom.json.Json;
import javax.json.google.gson.JsonObject;
import javaxcom.json.JsonReader;
import java.io.StringReadergoogle.gson.JsonParser;

public class ParseJWT {
    public static void main(String[] args) {
     public String parseClientId(String token) {
              // 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));
       using Gson
        JsonObject jsonObject = jsonReaderJsonParser.readObjectparseString();
        jsonReader.closepayload).getAsJsonObject();
 
                // Extract the client_id
            String clientId = jsonObject.getStringget("client_id").getAsString();
            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)

...