jwillemsen / daikin_onecta

Home Assistant Integration for devices supported by the Daikin Onecta App
https://github.com/jwillemsen/daikin_onecta
GNU General Public License v3.0
251 stars 9 forks source link

[Issue]: OAuth failed - invalid_grant - token was issued to another client #187

Closed MicheleM42 closed 3 months ago

MicheleM42 commented 4 months ago

Good afternoon,

Since 3 days I'm trying to get this integration to work, but without success. I signed up for the developer account, I created the APP as per instructions: image

I get redirected to the Daikin website, I give permission, I link the account to my HA instance giving my internet address (not the local one) and when I get redirected to HA, this is the error: image

This is the log:

2024-05-09 16:17:31.812 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Error resolving OAuth token: 400, message='Bad Request', url=URL('https://idp.onecta.daikineurope.com/v1/oidc/token')
2024-05-09 16:21:24.506 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Resumed OAuth configuration flow
2024-05-09 16:21:24.513 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Creating config entry from external data
2024-05-09 16:21:24.514 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://idp.onecta.daikineurope.com/v1/oidc/token
2024-05-09 16:21:24.777 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Token request for daikin_onecta_qfiglpn5zwadxrp3xxxxxxxx failed (invalid_grant): The provided authorization code or refresh token was issued to another client.
2024-05-09 16:21:24.777 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Error resolving OAuth token: 400, message='Bad Request', url=URL('https://idp.onecta.daikineurope.com/v1/oidc/token')

I deleted everything I found in my HA instance related to the old daikin residential integration. I've tried to delete the daikin app in dev portal and refresh the tokens 10 times, changing browser and deleting cookies. But nothing helped. Could you please help me to solve the issue? thanks Michele

jwillemsen commented 4 months ago

Have you tried the default redirect uri as mentioned in the readme as part of the application you configured at the daikin website?

jwillemsen commented 4 months ago

Have you restarted HA? Have you installed my home assistent? Have you tried to link to your local HA ip address?

MicheleM42 commented 4 months ago

In my very first try some days ago I put my HA address. But then I deleted the app and put https://my.home-assistant.io/redirect/oauth I've tried restarting. I've just tried my home assistant (actually, I only added "my" to the configuration.yaml. Not sure it's enough). image

And I also tried to put my local IP in the link account page. Try also the other method you explained after in the readme: image Still nothing.

jwillemsen commented 4 months ago

I have no idea at this moment how to solve this, please open an issue on HA core to ask for a feature to retrieve the redirect_uri as used by HA so that you can use the same uri at the daikin portal

jjacobsson commented 4 months ago

Just chiming in here to say I suffer the same issue.

2024-05-09 20:05:28.841 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Resumed OAuth configuration flow
2024-05-09 20:05:28.888 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Creating config entry from external data
2024-05-09 20:05:28.888 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://idp.onecta.daikineurope.com/v1/oidc/token
2024-05-09 20:05:29.215 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Token request for daikin_onecta_<REDACTED> failed (invalid_grant): The provided authorization code or refresh token was issued to another client.
2024-05-09 20:05:29.215 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Error resolving OAuth token: 400, message='Bad Request', url=URL('https://idp.onecta.daikineurope.com/v1/oidc/token')
jwillemsen commented 4 months ago

Created an upstream issue https://github.com/home-assistant/core/issues/117169. I did had this on my system also when starting, but after a HA restart and using https://my.home-assistant.io/redirect/oauth as redirect uri it now works

jjacobsson commented 4 months ago

Nice!

I noted you wrote "Home Assistant OS" as installation type, I am using the container in a kubernetes cluster... which probably makes things more complicated by several miles. I imagine that it won't be enough for me to know what Home Assistant sends as redirect_uri, I will need a way to actually set it... maybe.... I don't know, honestly guessing here :D

jwillemsen commented 4 months ago

Maybe contact @Daikin-Europe, maybe they can find what you are sending

jwillemsen commented 4 months ago

Did you got it working?

jjacobsson commented 4 months ago

@jwillemsen sorry, I have not been able to tinker with this, am out of town until this weekend!

MicheleM42 commented 4 months ago

I could write either to Daikin or HA Core team, but I'm a total noob and not sure what to ask..and I'm afraid of the questions I could get as response :D

jwillemsen commented 4 months ago

Send them the error and what you already tried, you can also add a link to this issue

jwillemsen commented 4 months ago

Any updates?

muarqdnph4VPV6dyh commented 4 months ago

Hi,

I don't know if I am right here but maybe I am lucky. I wanted to add the Daikin Onecta Integration to my Home Assistant, but I have problems with the Daikin Developer Portal. In particular I am not able to login to https://developer.cloud.daikineurope.com/

When I go to the site I see the "Continue with SSO" button. When I click it I get redirected to https://id.daikin.eu/ where I can insert my credentials. This seems to work. However afterwards I am again redirected to the "Continue with SSO" button. If i click it again it just goes back and I am just stuck in an endless SSO loop.

What I also see is that the url in my browser is: https://developer.cloud.daikineurope.com/login?loginError=internal+error&loginSuccess=false

This happens every time, on every browser, with and without private mode. So it seems the issue is on Daikin side. Did anyone else also had this issue and know how to get arounad this? Or does someone know where / how I can contact Daikin support?

Thanks in advance.

jwillemsen commented 4 months ago

See https://developer.cloud.daikineurope.com/docs/b0dffcaa-7b51-428a-bdff-a7c8a64195c0/business_validation for a email address to contact Daikin

muarqdnph4VPV6dyh commented 4 months ago

Thanks for the quick answer, but unfortunately no luck. I also only get redirected to the "Continue with SSO" page when I click this link where I am stuck in a loop.

jwillemsen commented 4 months ago

Have you restarted your system or use a different PC?

jjacobsson commented 4 months ago

Had a similar problem the other day, clear your browsers cookies/try a private browser window.

I have made some more attempts at getting to work, tried to read the code for both the integration and home assistant to see if I could deduce what the redirect_url actually gets set to. But I have made no progress. Is there a way to get more verbose logging perhaps?

fre 24 maj 2024 kl. 15:35 skrev muarqdnph4VPV6dyh @.***

:

Thanks for the quick answer, but unfortunately no luck. I also only get redirected to the "Continue with SSO" page when I click this link where I am stuck in a loop.

— Reply to this email directly, view it on GitHub https://github.com/jwillemsen/daikin_onecta/issues/187#issuecomment-2129553391, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAASHYUASGKFSTJET5X3YG3ZD462FAVCNFSM6AAAAABHO52GDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRZGU2TGMZZGE . You are receiving this because you commented.Message ID: @.***>

jwillemsen commented 4 months ago

All authorization is handled by HA, maybe ask if they can add some more logging to the HA application credentials support? I have created an issue to ask for a way to retrieve the redirect_uri, see https://github.com/home-assistant/core/issues/117169

jjacobsson commented 4 months ago

Yepp, saw the issue! Gj!

One thing I noted is that the code for HA seems to have moved on from the version I have running, the line numbers in the logs don’t line up with the source. Perhaps fixes are coming.

I tried to find the python for what I actually have running but I have no idea where that lives inside this docker image :D

fre 24 maj 2024 kl. 16:12 skrev Johnny Willemsen @.***>:

All authorization is handled by HA, maybe ask if they can add some more logging to the HA application credentials support? I have created an issue to ask for a way to retrieve the redirect_uri, see home-assistant/core#117169 https://github.com/home-assistant/core/issues/117169

— Reply to this email directly, view it on GitHub https://github.com/jwillemsen/daikin_onecta/issues/187#issuecomment-2129634268, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAASHYQ2MBWYVB2JHAOHULTZD5DFLAVCNFSM6AAAAABHO52GDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRZGYZTIMRWHA . You are receiving this because you commented.Message ID: @.***>

muarqdnph4VPV6dyh commented 4 months ago

Have you restarted your system or use a different PC?

yes, even tried it on a different PC and on my Phone, everytime the same result. But in the meantime i found a general Daikin support form. Hopefully they can resolve this or forward it internally to the right team.

jjacobsson commented 3 months ago

Ok. So I had some time now to dig into this. And the problem is that you have hard-coded the client id & secret in config_flow.py on lines 93 & 94. These should be the values you make the user enter as part of the flow.

By the way you should probably generate new ones for yourself. Ahem.

jjacobsson commented 3 months ago

Ok now that is strange.

When checking the repo here, you don't have those lines. But when I check the .py files in install that were grabbed by HACS, I have hard-coded client id & secret....

jwillemsen commented 3 months ago

Do you have installed the latest version, in the past we had a client id/secret which was provided by Daikin

jjacobsson commented 3 months ago

That must be the problem... I guess I am fooled when I click HACS->Integrations->Daikin Onecta on my instance I am taken to this page:

bild

But I guess that is just pulling data of github and not actually telling me anything about what I have installed...

jjacobsson commented 3 months ago

No, re-installed. I still get a version installed that has a hard-coded client_id/secret.

jwillemsen commented 3 months ago

Try to remove it completely and install a fresh copy, did also had cases where HACS installed something differently as I thought

jwillemsen commented 3 months ago

Current installed version should be visible under config/integrations/integration/daikin_onecta, under device settings

jjacobsson commented 3 months ago

bild I will try clean.

jjacobsson commented 3 months ago

Removed the repository in HACS. Removed the folder /config/custom/components/daikin_onecta. Restarted home assistant. Re-added the repository in HACS. Re-downloaded.

I now have version 4.1.3 installed and the configuration flow worked flawlessly.

MicheleM42 commented 3 months ago

I'm out of home these days so I can't operate on Ha yet. However I checked and I confirm I have id and secret hardcoded on my instance too. I think we can close the issue. Many thanks for the kind support!