Trouble authenticating into InfluxDB v2

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
fodome
New user
Posts: 7
Joined: 16 Feb 2022, 00:43

Trouble authenticating into InfluxDB v2

#1 Post by fodome » 18 Feb 2022, 05:32

Hey guys,
I'm trying to get my ESPEasy Generic HTTP Advanced controller to connect to InfluxDB v2. This is the header that I am specifying:
HTTP_Config.jpg
HTTP_Config.jpg (47.44 KiB) Viewed 9189 times
I get the following error message:
3117316 : Error : HTTP : C011 POST... HTTP code: 401 {"code":"unauthorized","message":"unauthorized access"}

Here is the POST in Wireshark:
Wireshark_post.jpg
Wireshark_post.jpg (226.87 KiB) Viewed 9189 times
Here is the response in Wireshark:
Wireshark_response.jpg
Wireshark_response.jpg (40.65 KiB) Viewed 9189 times
Also, the following CURL command works great:

curl.exe -i -XPOST "http://localhost:8086/api/v2/write?org= ... recision=s" --header "Authorization: Token qcyFqXX5fgYgv4FudNN7n_9Y9KfjwVJ0keUuSR_srlkZfUD6T6Sa1tN4e__BE4d56-SXUHZNfKyq6heAx3-lCQ==" --data-binary "Environment,device=ESP32,taskname=BME280 humidity=28.5,temperature=24.5,pressure=102.3 1645156813"

Have I configured the HTTP header correctly for the authorization?

Thanks in advance,

Fodome

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Trouble authenticating into InfluxDB v2

#2 Post by TD-er » 18 Feb 2022, 08:41

Can you check if ESPEasy is set to wait for an acknowledgement?
For SendToHttp like commands, make sure to check (Tools->Advanced) "SendToHTTP wait for ack"

In the controller, it is part of the controller settings, but maybe best to also check the option in the Tools->Advanced page.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Trouble authenticating into InfluxDB v2

#3 Post by TD-er » 18 Feb 2022, 08:42

And do you also have a wireshark capture of what is sent/received when using the curl command?

fodome
New user
Posts: 7
Joined: 16 Feb 2022, 00:43

Re: Trouble authenticating into InfluxDB v2

#4 Post by fodome » 01 Mar 2022, 15:47

I did set the controller to wait for an acknowledgement, but even then I am getting the same error message as before.

I do not have an advanced section in my tools page. I'm using the custom ESPEasy configuration with just the BME280 plugin and a few controllers (Domoticz HTTP, Domoticz MQTT, Generic HTTP and Generic HTTP Advanced), so I cannot check for the wait for acknowledgement there.

When I use curl, this is the POST that I get:
Wireshark_curl_post.jpg
Wireshark_curl_post.jpg (147.32 KiB) Viewed 8965 times
And this is the response:
Wireshark_curl_response.jpg
Wireshark_curl_response.jpg (135.01 KiB) Viewed 8965 times

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Trouble authenticating into InfluxDB v2

#5 Post by Ath » 01 Mar 2022, 16:07

Your OP has "Authorization: Basic <username> Credentials: : " with response "Unauthorized" (status code 401), and your Curl attempt uses "Authorization: Token <tokendata>" that is accepted (status code 204), so your manually pasted Authorization in the Header apparently isn't overwriting the default username/password.
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Trouble authenticating into InfluxDB v2

#6 Post by Ath » 01 Mar 2022, 20:22

fodome wrote: 01 Mar 2022, 15:47 I do not have an advanced section in my tools page. I'm using the custom ESPEasy configuration with just the BME280 plugin and a few controllers (Domoticz HTTP, Domoticz MQTT, Generic HTTP and Generic HTTP Advanced), so I cannot check for the wait for acknowledgement there.
It is really hard to create an ESPEasy that doesn't have that Advanced settings page, why would you want to do that? The smaller .bin size won't make it run faster, but only makes it harder to configure things, as that page has a lot of settings that can help you out when facing issues, like above.

That doesn't mean the solution is there, but having that makes finding a solution easier.
/Ton (PayPal.me)

elfrinjo
Normal user
Posts: 11
Joined: 25 May 2022, 23:53

Re: Trouble authenticating into InfluxDB v2

#7 Post by elfrinjo » 13 Jul 2022, 15:59

Hi,
I just found this post when trying to use influxdbv2 as well.

As it seems, it is currently not possible to _not_ send the basic auth information from the Credentials section.
I guess this this a bug and the header should not be sent or it should be taken from the Header field when Use Extended Credentials is unchecked.

Influxdb v2 will still accepts basic auth when used with the v1 legacy api. So this is my workaround:
Create a influxdb v1 user with

Code: Select all

 influx v1 auth create
Create a db to bucket mapping with

Code: Select all

influx v1 dbrp create
Add username and password to the controller-settings
Put the v1 endpoint and the newly mapped db-name into the URI field:

Code: Select all

/write?db=<DBNAME>

Cheers, Jörg

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests