david-streamlio / pulsar-nifi-bundle

NiFi Processor for Apache Pulsar
Apache License 2.0
16 stars 19 forks source link

PulsarClientOauthAuthenticationService Private key file field doesn't support Base64 encoded value. #85

Open olavgg opened 1 month ago

olavgg commented 1 month ago

Instead of creating a file for nifi, you should be able to add a base64 encoded value

This works with the Pulsar Client

String oauth2Creds = "{" +
                "\"type\":\"client_credentials\"," +
                "\"client_id\": \"" + clientId + "\"," +
                "\"client_secret\": \"" + clientSecret + "\"," +
                "\"issuer_url\": \"" + issuerUrl + "\"" +
                "}";
        String base64data = Base64.getEncoder().encodeToString(oauth2Creds.getBytes());
        String json = "{" +
                "\"type\":\"client_credentials\"," +
                "\"privateKey\":\"data:application/json;base64," + base64data + "\"," +
                "\"issuerUrl\":\"" + issuerUrl + "\"," +
                "\"audience\":\""+audience+"\"" +
                "}";
        var auth = AuthenticationFactory .create(AuthenticationOAuth2.class.getName(), json);

        client = PulsarClient.builder()
                        .serviceUrl(myPulsarUrl)
                        .authentication(auth)
                        .build();
david-streamlio commented 1 month ago

+1