Use NiFi "sensitive" parameters to generate JSON payload for HTTP authentication - apache-nifi

Using Apache Nifi v1.19.1, I need to make an HTTP POST request via the InvokeHTTP processor in order to authenticate with an API before I can upload the FlowFile via another InvokeHTTP processor.
I've configured the username/password for the API in a Parameter Context and marked them (as you might expect) as "Sensitive Value".
Now, when I try to reference those parameters in the GenerateFlowFile processor's Custom Text property, I get the error:
'Custom Text' is invalid because the property 'Custom Text' cannot reference Parameter 'username' because the Sensitivity of the parameter does not match the Sensitivity of the property.
(And again for the password parameter.) I understand why this is, but it seems like an interesting limitation. At some point I need to be able to utilize that username/password in my flow.
Is there a solution to this?

Related

Nifi API Authentication - Access Token

I'm attempting to collect details about all processors on two installed instances of Nifi, versions 1.19.0 and 1.20.0. I want to use Nifi to do this so I can perform some minor ETLs and save the resultant dataset in a database. Both instances are configured as standalone authentication with SSL.
However, when I configure the InvokeHTTP processor how I think it should be to aquire a token, I'm getting a 400 status code and a response.body of "The username and password must be specified." on both instances.
Here's the super basic flow:
Nifi Flow
Here's what the error looks like:
Attributes of failed response
Here's the current config of the InvokeHTTP processor on the 1.20.0 instance which we can focus on from here out since they are both responding similarly.
Postman - InvokeHTTP Config
When I run the request with Postman, I get the expected token in the response body. And I'm able to make subsequent requests (the above config was a response from https://nifi06:8443/nifi-api/processors/39870615-0186-1000-e7d7-c59fa621ca7d in Postman).
I've tried the following:
Adding dynamic attributes for username/password as in the above configuration.
I've added them as JSON to the preceding Generate FlowFile processor's custom text.
And I've also tried using the Request Username/Request Password properties of the InvokeHTTP processor.
All return with the same response.body of "The username and password must be specified."
This seems it should be really simple and I'm sure I've been staring at it too long to see what I'm missing. Can anyone tell me where I need to specify the username/password?
Thanks.

Nifi invoke http how to get a value and add as Header during post data

I have a NiFi flow which needs to post the data to some other server, before posting it needs to fetch a value from my internal server or Nifi Distributed cache.
And add that Value in to Http header before posting the data, also update when gets particular error code 401.
Below is the flow I am trying, all green processor I could do but stuck at getting the value and adding in invoke http header . What are other process I can make us to achieve this .
https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.9.0/org.apache.nifi.processors.standard.InvokeHTTP/
according to documentation on http code 401 InvikeHTTP routes file to No Retry relation.
also flow file should contain some response attributes including invokehttp.status.code
so, you could use RouteOnAttribute processor to redirect flow file to your external token processor only when invokehttp.status.code=401.

Does HandleHttpProcessor supports "CORS"(Access-Control-Allow-Origin)

I just started working with HandleHttpprocessor in Apache Ni-Fi ,trying to figure out if I need to configure anything in HandleHttpprocessor to support Access-Control-Allow-Origin issue.
HandleHttpRequest processor can only accept a request and it does not send any response to the client. Therefore you need to combine it with HandleHttpResponse processor in order to send the response back to the client.
You can set custom headers in HandleHttpResponse processor by adding custom properties to it. To do that you can add a dynamic property by clicking the 'plus' sign, then enter its name which will be the name of the custom HTTP header.
Ex: Access-Control-Allow-Origin: *

Apache Nifi : How to pass post params and capture response from post API - traditional non rest, non json API

I'm trying to pull data from a post API that expects authentication and request parameters as part of the request body. I guess, what they do is access the data from the post variables.
What I have seen so far in documentation is how to send POST via JSON or headers. In my case, no headers just the post body parameters.
call to this api via curl --data option works just fine.
curl --data "username=xyz&password=xyz&function=xyz" http://example.com/api.php
How can I replicate above call in nifi?
I have tried multiple methods without success. Latest has been Generate flow file, update attributes (where i fill in the parameters), invoke http then putfile.
But I'm getting errors - the api is not abe to authenticate my request.
Thanks
If you need to send the following data in body, then put it into content of your flowfile.
username=xyz&password=xyz&function=xyz
The easiest way to put it into the Custom Text property of the GenerateFlowFile processor.
Usually for this kind of body you have to provide content type header:
content-type: application/x-www-form-urlencoded
If you don't need any additional headers then you don't have to define any additional attributes of the flow file.

get response from InvokeHTTP POST

New to NiFi!
I'm using InvokeHTTP nifi processor (using this link as an example to implement my flow http://www.tomaszezula.com/2016/10/30/nifi-and-http-post-configuration/). I currently need to do POST in order to authenticate against a server I am using. I am able to POST successfully. However, I need to be able to get the data returned from the response of the POST that was executed. When I look at InvokeHTTPs output into the success queue all I see is the body which I had posted. Is there anyway for me to get the response into a flowfile?
Thanks in advance!
Apache NiFi's InvokeHTTP processor sends the response content to a separate relationship from the original flowfile. You will want to separately route this response relationship.
InvokeHTTP also has a Put Response Body In Attribute property, which you can set to capture the response as a attribute, rather than a separate flowfile. This might be useful for an auth token.

Resources