RobertD502 / home-assistant-flair

Custom component for Home Assistant Core for Flair pucks, vents, rooms, structures, and minisplits
MIT License
96 stars 12 forks source link

Flair authentication failed. Are your credentials correct? - Creds are correct, debug logging does not help troubleshoot #6

Closed mlebaugh closed 3 years ago

mlebaugh commented 3 years ago

I've been using this container to push flair data to home assistant via mqtt. Its been working well for me for a year, but I stumbled on your project which is a much better solution than the container I hacked together.

Unfortunately, I encounter an issue when adding the integration "Flair authentication failed. Are your credentials correct?". The credentials are correct, so I enabled debug logging for the component but didn't find anything that indicated what the issue might be.

Installed via HACS - v0.0.4

RobertD502 commented 3 years ago
Flair config flow

I just deleted the integration, restarted HA, and added it again without a problem. I'll need to add logging to the config flow in an upcoming release. The config flow essentially takes your credentials and logs in. Try rebooting the host machine (of Home Assistant) and then add the integration.

Edit: I saw the MQTT method you were using and it used apostrophes around the client ID and client secret. This integration doesn't use apostrophes around the client ID and client secret. If you were doing so, this would explain the failure to log in to your Flair account via this integration.

RobertD502 commented 3 years ago

@mlebaugh any updates on this?

mlebaugh commented 3 years ago

Sorry for the delay, got caught up on some work tasks. I deleted the integration, restarted the server its running on, reinstalled etc. I tried all the normal things. I also did not use apostrophes when attempting through the automation. I'll probably have to wait for additional debugging logs, unless you have some other troubleshooting ideas. Thanks again for taking a look.

RobertD502 commented 3 years ago

Can you send this curl command via your terminal and let me know if it returns an authentication token:

curl -X POST 'https://api.flair.co/oauth2/token?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&scope=thermostats.view+structures.view+structures.edit&grant_type=client_credentials' -H 'Content-Type: application/x-www-form-urlencoded' -F 'client_id="CLIENT_ID"' -F 'client_secret="CLIENT_SECRET"' -F 'scope="thermostats.view+structures.view+structures.edit"' -F 'grant_type="client_credentials"'

Be sure to put your client ID and Client secret where CLIENT_ID and CLIENT_SECRET are defined after "-F".

For example where it says -F 'client_id="CLIENT_ID"' it should be -F 'client_id="YourClientID"'

Do the same for the secret and be sure to keep all quotation marks and apostrophes where they are.

Edit: sorry for the formatting. This should all be a single curl command so you may have to adjust any extra spaces github added as I am posting from mobile.

mlebaugh commented 3 years ago

here is what I ran, I replaced redacted_* with what I replaced.

matt@Matts-MBP ~ % curl -X POST 'https://api.flair.co/oauth2/token?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&scope=thermostats.view+structures.view+structures.edit&grant_type=client_credentials' -H 'Content-Type: application/x-www-form-urlencoded' -F 'client_id="redacted_id"' -F 'client_secret="redacted_secret"' -F 'scope="thermostats.view+structures.view+structures.edit"' -F 'grant_type="client_credentials"' {"error": "invalid_client"}% matt@Matts-MBP ~ %

RobertD502 commented 3 years ago

Sorry, it looks like the updated Flair API documentation isn't correct/doesn't work yet (they will be moving to oauth2 in the future). Could you please use this curl command instead and be sure to replace CLIENT_ID and CLIENT_SECRET in the URL with your client ID and client secret.

curl -X POST 'https://api.flair.co/oauth/token?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&scope=thermostats.view+structures.view+structures.edit&grant_type=client_credentials' -H 'Content-Type: application/x-www-form-urlencoded'

mlebaugh commented 3 years ago

That returns a token. See below

matt@Matts-MBP ~ % curl -X POST 'https://api.flair.co/oauth/token?client_id=redacted_id&client_secret=redacted_secret&scope=thermostats.view+structures.view+structures.edit&grant_type=client_credentials' -H 'Content-Type: application/x-www-form-urlencoded' {"access_token": "redacted_token", "expires_in": 3600, "token_type": "Bearer", "scope": "thermostats.view structures.view structures.edit"}%
matt@Matts-MBP ~ %

RobertD502 commented 3 years ago

@mlebaugh update the Flair integration to 0.0.4.1 (most recent release). It should now log any exceptions raised by Flair's API during initial set up as errors in Home Assistant. Let me know what your log shows whenever you get a chance to test it out so we can narrow down the problem.

mlebaugh commented 3 years ago

Well this is interesting.

2021-08-11 21:40:39 ERROR (MainThread) [custom_components.flair.config_flow] Unable to connect to Flair: Failed to Log In 2021-08-11 21:40:39 ERROR (MainThread) [custom_components.flair.config_flow] ApiError<HTTP Response: 404>

Previously I ran that curl command on my laptop, to ensure I'm not having any issues with my container I attached to it and issued the same command, it returned a token there too. Not really sure why I'd be getting a 404 from the integration, but not directly from the container.

RobertD502 commented 3 years ago

So the config flow does more than just log in and grab the token. After logging in, it also discovers all rooms. Do you have rooms set up in the mobile flair app?

mlebaugh commented 3 years ago

Yes 7 rooms, 1 puck, and probably ~14 vents.

RobertD502 commented 3 years ago

Edit the config_flow.py file and replace discover_rooms located on line 51 with discover_pucks. Save the changes, restart home assistant, and try again.

mlebaugh commented 3 years ago

No luck, same error.

RobertD502 commented 3 years ago

How are you running Home Assistant? I'm starting to think that this issue is related to your personal setup as others have not had this problem.

mlebaugh commented 3 years ago

I'm running home-assistant in an unsupervised docker container, which I think is pretty common. I've spun up another test home-assistant container with nothing but the custom-config directory and tried to set this up there and had the same issue (on multiple hosts).

That said, I'm thinking there is something is unexpected with my flair setup. I don't mind sharing my flair creds for you to take a look, just don't know the best way to do that.

Thanks again for your help.

RobertD502 commented 3 years ago

Sure just send them my way. Best way to do it would be via e-mail to dr.robert1316 at gmail.com

RobertD502 commented 3 years ago

Notes: