1

I am trying to open NIFI using an WPF application which is running in secured mode. After analying found options only for opening secured url with basic authorization only as given in below link. https://social.msdn.microsoft.com/Forums/windows/en-US/21674c95-7389-46e2-abc3-7019556e2eb0/basic-authentication-in-webbrowser-control?forum=winforms

This is not working for NIFI where we used "Bearer token" here.

   public static void NavigateWithAuthorization(WebBrowser browser, Uri uri)
    {
        byte[] authData = System.Text.Encoding.UTF8.GetBytes("user:password");
        string authHeader = "Authorization: Bearer " + Convert.ToBase64String(authData) + "\r\n" + "User-Agent: MyUserAgent\r\n";
        browser.Navigate(uri, "", null, authHeader);
    }
kayal
  • 123
  • 12

1 Answers1

0

If you are using the C# HttpClient, you need to add a header with the token you received on the first call to all subsequent requests (as noted for Basic Authentication here or OAuth here).

httpClient.DefaultRequestHeaders.Authorization = 
    new AuthenticationHeaderValue("Bearer", base64EncodedJWTReceivedFromNiFi);

If this is not sufficient to solve your problem, please post the complete code that you are trying to use and the actual error you are receiving.

Community
  • 1
  • 1
Andy
  • 13,916
  • 1
  • 36
  • 78
  • Hi Andy,I am not using HttpClient here. Please find the code details above. – kayal Apr 19 '17 at 04:29
  • That is because NiFi does not accept basic authentication (Base 64 of `username:password`) as a valid authentication mechanism. NiFi supports [three authentication mechanisms](https://nifi.apache.org/docs/nifi-docs/html/administration-guide.html#user-authentication) out of the box (can be extended with custom code) -- client certificates, LDAP(S), and Kerberos. If you are using client certs, every request must have the cert present. For LDAP or Kerberos, a `POST` to `/access/token` with the username and password returns a JWT token. – Andy Apr 19 '17 at 16:56
  • See [REST API - Access](https://nifi.apache.org/docs/nifi-docs/rest-api/index.html) for more details. As always, using the browser's Developer Tools to monitor the requests that NiFi makes is the best way to learn about and verify the API calls you wish to make from a different client. – Andy Apr 19 '17 at 16:56