Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

Highlighted

Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

New Contributor

we are very new to NIFI and working on 1st project - we have a requirement where we need to connect to API using -

Request an access token by sending your Client ID and Client Secret via HTTP Basic Authentication, using an HTTP POST request. The Client ID and Client Secret need to be encoded to Base64, using the UTF-8 character set, in the form of client_id:client_secret. A resource you can use for this purpose is https://www.base64encode.org/. This string is then passed as the Authorization header.

Please guide on how to proceed with this flow

We are searching this Community and found many good learning .

Any pointer will be really appreciated.

10 REPLIES 10

Re: Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

Hi,

Using the InvokeHTTP processor you just have to put your client_id in basic authentication username property and your client_secret in basic authentication password property. Everything else will be taken care of by the processor regarding the basic authentication.

Beside these properties, you have to give the API URL to request and you should be good to go. The content of the response to your request will be inside the flow files at the output of this processor.

7410-screen-shot-2016-09-07-at-30505-pm.png

Re: Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

New Contributor

@Pierre Villard i did try this using the below flow and added at the last put file but still struggling with the flow

Re: Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

Did you start the processors? on your screenshot, all the processors are stopped.

Re: Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

New Contributor

I did this and see the task and time is increasing but no change in bytes.

I used POST method because I saw the following . Does any property on header needs to be set

Request an access token by sending your Client ID and Client Secret via HTTP Basic Authentication, using an HTTP POST request

7432-untitled.png

Re: Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

Please add a GenerateFlowFile processor before InvokeHttp processor, and connect GFF to InvokeHttp. You need to have flow files generated going into InvokeHttp processor to have requests performed against your API.

You are correct for the method if your API asks for a POST method.

Re: Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

New Contributor

@pierre Villard

I did added the generate flow file and did see that stats are updating - till split jason processor. after that there was no change in processor. I am not able to debug the issue . can you suggest how to debug. What best practices we should follow to do error handling

7434-untitile-1.png

Re: Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

New Contributor

@ pierre Villard - Hi- I went thru your article posted in below link -

https://pierrevillard.com/2016/04/12/oauth-1-0a-with-apache-nifi-twitter-api-example/

In our API guide , I found that API uses use the OAuth 2.0 standard to authenticate all requests

The APIs are all accessed via REST invocations and return results in JSON format. The API use the OAuth 2.0 standard to authenticate all requests To authenticate to the API endpoint, we will need a token we send with every API call. To retrieve a token please follow the steps below- Request an access token by sending your Client ID and Client Secret via HTTP Basic Authentication, using an HTTP POST request. The Client ID and Client Secret need to be encoded to Base64, using the UTF-8 character set, in the form of client_id:client_secret. A resource you can use for this purpose is https://www.base64encode.org/.

This string is then passed as the Authorization header. The API will respond with an access token Note: Tokens are only valid for one hour. After one hour a new token is required. Pass the token as the Authorization header to access the API resources: API resource data is returned:

I assume there were some more steps needed in between which is missing to make the correct flow.

Can you please guide

Re: Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

New Contributor

@pierre Villard

thanks for your reply . I made the below flow

7429-untitled-1.png

7430-untitled-2.png

above for split jason and then use the below for evaluate jason path

7431-untitled-3.png

after running i am not able to see any progress .

Re: Connecting to API using by Client ID and Client Secret via HTTP Basic Authentication

With your current flow, you need to generate some flow files to initiate the flow. For this purpose you can use GenerateFlowFile with 0B of data and with a custom scheduling strategy to request your API every X seconds/minutes/hours, etc... And you connect it to InvokeHttp processor.

Don't have an account?
Coming from Hortonworks? Activate your account here