tuya / tuya-homebridge

Homebridge custom plugin for controlling Powered by Tuya (PBT) devices in HomeKit. This plugin is officially maintained by the Tuya Developer Team.
MIT License
345 stars 178 forks source link

Token expired code 1010 #296

Closed ipa64 closed 1 year ago

ipa64 commented 1 year ago

Describe the bug After a plugin restart (or restart Homebridge) all is working as expected (1x Tuya monitoring plug, 1x Tuya miniSwitch can be ON/OFF from homekit), but after un bit less than 2 hours I got a token expired code 1010 in the log file (debug ON).

Expected behavior The plugin should refresh the token before it expired. I guess if the first token could be created it should not be a configuration problem.

**Device info (please complete the following information, which can be found in [log]

TuyaOpenAPI request: method = post, endpoint = https://openapi.tuyaus.com, path = /v1.0/devices/eb2c4c4425902f8253dqv0/commands, params = null, body = {"commands":[{"code":"switch_1","value":false}]}, headers ={"t":"1664956300703","client_id":"xxxxxxxxxxx","nonce":"xxxxxxxx","Signature-Headers":"client_id","sign":"DCD0AC982E6C15E227197E9F4366718Xxxxxxx","sign_method":"HMAC-SHA256","access_token":"03ff96847228798b7f2e4f23c306exxx","lang":"en","dev_lang":"javascript","dev_channel":"homebridge","devVersion":"1.5.0"} TuyaOpenAPI response: {"code":1010,"msg":"token is expired","success":false,"t":1664956301xxx,"tid":"8cbec1ac448211ed820d56272bexxx"} path = /v1.0/devices/eb2c4c4425902f8253dqv0/commands

Additional context Add any other context or logs about the problem here.

ipa64 commented 1 year ago

Now it’s still working after more than 12h without any issue ! Wait and see

ipa64 commented 1 year ago

I got this issue only first day, not anymore after ! So I close

ipa64 commented 1 year ago

Hi, was working few weeks, then these last days again code 1010 token expired Just restart the plugin and it works again for a while

0x5e commented 1 year ago

Hi @ipa64, please try @0x5e/homebridge-tuya-platform beta version, it reimplemented the login and token fetch procedure. It should work now.

0x5e commented 1 year ago

By the way, what projectType are you using? Is it Custom?

ipa64 commented 1 year ago

Do you mean Development Method?

My project settings: Industry=Smart Home Development Method=Smart Home

ipa64 commented 1 year ago

Hi @ipa64, please try @0x5e/homebridge-tuya-platform beta version, it reimplemented the login and token fetch procedure. It should work now.

Thank you, on the way

0x5e commented 1 year ago

OK. Could you provide the request and response logs of /v1.0/iot-01/associated-users/actions/authorized-login, /v1.0/token, if the beta version still not work?

ipa64 commented 1 year ago

OK. Could you provide the request and response logs of /v1.0/iot-01/associated-users/actions/authorized-login, /v1.0/token, if the beta version still not work?

Yes of course ! Thank you

ipa64 commented 1 year ago

OK. Could you provide the request and response logs of /v1.0/iot-01/associated-users/actions/authorized-login, /v1.0/token, if the beta version still not work?

Seems to have the same issue, but not really sure, because the option to activate debug log is missing, is there another way to enable debug ?

0x5e commented 1 year ago

Add -D params when start homebridge: homebridge -D Or if you are using web, the debug mode can be found in the setting page.

ipa64 commented 1 year ago

Add -D params when start homebridge: homebridge -D Or if you are using web, the debug mode can be found in the setting page.

precisely it is not here on the setting page of in the beta version

I have just found the debug switch in homebridge settings, with the plugin v1.5 it was one on the setting plugin

0x5e commented 1 year ago

Yeah I mean homebridge setting page :)

ipa64 commented 1 year ago

OK. Could you provide the request and response logs of /v1.0/iot-01/associated-users/actions/authorized-login, /v1.0/token, if the beta version still not work?

here we are, but don't if it's what you are asking for :-)

`[10/25/2022, 7:53:48 PM]  [@0x5e/homebridge-tuya-platform]  TuyaOpenAPI response: path = /v1.0/iot-01/associated-users/actions/authorized-login, data = {"result":{"access_token":"97aad7563f71f89a342b4620a59c3c59","expire_time":7200,"platform_url":"https://openapi.tuyaus.com","refresh_token":"2d1ad6412ab362f086101eca3a108d38","uid":"az1664451251132ekqP5"},"success":true,"t":1666702428447,"tid":"11664f98546411ed918366cd25043e07"}

[10/25/2022, 9:52:50 PM]  [@0x5e/homebridge-tuya-platform]  TuyaOpenAPI response: path = /v1.0/token/2d1ad6412ab362f086101eca3a108d38, data = {"code":1010,"msg":"token is expired","success":false,"t":1666709570756,"tid":"b294e393547411ed918366cd25043e07"} `

0x5e commented 1 year ago

OK. Could you provide the request and response logs of /v1.0/iot-01/associated-users/actions/authorized-login, /v1.0/token, if the beta version still not work?

here we are, but don't if it's what you are asking for :-)

`[10/25/2022, 7:53:48 PM]



[@0x5e/homebridge-tuya-platform]



TuyaOpenAPI response: path = /v1.0/iot-01/associated-users/actions/authorized-login, data = {"result":{"access_token":"97aad7563f71f89a342b4620a59c3c59","expire_time":7200,"platform_url":"https://openapi.tuyaus.com","refresh_token":"2d1ad6412ab362f086101eca3a108d38","uid":"az1664451251132ekqP5"},"success":true,"t":1666702428447,"tid":"11664f98546411ed918366cd25043e07"}

[10/25/2022, 9:52:50 PM]



[@0x5e/homebridge-tuya-platform]



TuyaOpenAPI response: path = /v1.0/token/2d1ad6412ab362f086101eca3a108d38, data = {"code":1010,"msg":"token is expired","success":false,"t":1666709570756,"tid":"b294e393547411ed918366cd25043e07"}

`

That's wierd. can you also provide the request part? there's only response. the sensitive part can be replaced

ipa64 commented 1 year ago

This is it ? (Note I am not sure what sensitive part are)

TuyaOpenAPI request: method = get, endpoint = https://openapi.tuyaus.com, path = /v1.0/token/2d1ad6412ab362f086101eca3a108d38, params = undefined, body = null, headers = {"t":"1666709569834","client_id":"xxxxxxxxxxxxxxx","nonce":"xxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxx","Signature-Headers":"client_id","sign":"xxxxxxxxxx","sign_method":"HMAC-SHA256","access_token":"","lang":"en","dev_lang":"javascript","dev_channel":"homebridge","devVersion":"1.6.0-beta.12"}

0x5e commented 1 year ago

yes, let me have a test.

0x5e commented 1 year ago

1.6.0-beta.14 should working now. @ipa64 There was some mistake in the code.

github-actions[bot] commented 1 year ago

Stale issue. we will close the issue soon. If this issue has not been resolved, please update the issue and contact us in time.