Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access key/token improperly parsed #29

Closed
cgarrovillo opened this issue Jun 6, 2021 · 28 comments
Closed

Access key/token improperly parsed #29

cgarrovillo opened this issue Jun 6, 2021 · 28 comments
Labels
code 1106 good first issue This is a good issue for newcomers

Comments

@cgarrovillo
Copy link

plugin 1.1.7
node 14.17

After proper setup following this tutorial: https://developer.tuya.com/en/docs/iot/Tuya_Homebridge_Plugin?id=Kamcldj76lhzt

accessKey in config.json seems to be parsed incorrectly:
image

when accessKey is changed to accessToken, a different error occurs:

{
    "bridge": {
        "name": "Homebridge 4547",
        "username": "***********************",
        "port": ***********************,
        "pin": "***********************"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "options": {
                "username": "***********************",
                "password": "***********************",
                "accessId": "***********************",
-                 "accessKey": "6"***********************"b",
+                "accessToken": "6"***********************"b",
                "lang": "en",
                "projectType": "2",
                "appSchema": "tuyaSmart",
                "endPoint": "https://openapi.tuyaus.com",
                "countryCode": 123456,
                "debug": true
            },
            "name": "TuyaPlatform",
            "platform": "TuyaPlatform"
        }
    ]
}

image

@Hanh94
Copy link
Contributor

Hanh94 commented Jun 6, 2021

Hi @cgarrovillo, Please refer to this comment and this comment, That might solve your problem

@cgarrovillo
Copy link
Author

Hi @cgarrovillo, Please refer to this comment and this comment, That might solve your problem

This is on a new project created June 5.
image

@Hanh94
Copy link
Contributor

Hanh94 commented Jun 7, 2021

Hi @cgarrovillo , If you are already following the Tuya IoT Platform Configuration Guide Using Smart Home PaaS to set up step by step. I noticed in the config file that the "countryCode" is "123456". Verify that your "endPoint "is the US. This countryCode should be "1".Please try it again.

@cgarrovillo
Copy link
Author

Hi @cgarrovillo , If you are already following the Tuya IoT Platform Configuration Guide Using Smart Home PaaS to set up step by step. I noticed in the config file that the "countryCode" is "123456". Verify that your "endPoint "is the US. This countryCode should be "1".Please try it again.

It is actually 1, I just wanted to "anonymize" the data before posting it here 😄

@Hanh94
Copy link
Contributor

Hanh94 commented Jun 8, 2021

Hi @cgarrovillo , If you are already following the Tuya IoT Platform Configuration Guide Using Smart Home PaaS to set up step by step. I noticed in the config file that the "countryCode" is "123456". Verify that your "endPoint "is the US. This countryCode should be "1".Please try it again.

It is actually 1, I just wanted to "anonymize" the data before posting it here 😄

General permission issues can be resolved in Tuya IoT Platform Configuration Guide Using Smart Home PaaS , Please carefully follow the steps in the document configuration, and get the corresponding values to configure in the config.json, do not need to change the format in the config.json

@Hanh94
Copy link
Contributor

Hanh94 commented Jun 8, 2021

Account Permissions:
1.Your cloud project on the Tuya IoT Platform was created after May 25, 2021.
2.On the Tuya IoT Platform, you have linked devices by using Tuya Smart or Smart Life app in your cloud project.
3.You entered the correct account and password of the Tuya Smart or Smart Life app in the Account and Password fields.

Please check this.

@Hanh94 Hanh94 added good first issue This is a good issue for newcomers question Further information is requested labels Jun 18, 2021
@rikray02
Copy link

Hello,

I tried to use this new plugin, but it doesn't work and i receive this message:

Capture d’écran, le 2021-06-18 à 23 46 05

My configuration of JASON file is:
Capture d’écran, le 2021-06-18 à 23 44 24

My configuration of Tuya Web Platform is:
Capture d’écran, le 2021-06-18 à 23 39 11
Capture d’écran, le 2021-06-18 à 23 40 49
Capture d’écran, le 2021-06-18 à 23 41 48

I use the same email address for my account of the cell apps and Web Platform but the password is different.

I'm absolutely sure that my credential is OK on JASON file. An idea why i receive this error message?

Thanks for your help!
Richard

@cgarrovillo
Copy link
Author

Hello,

I tried to use this new plugin, but it doesn't work and i receive this message:

Capture d’écran, le 2021-06-18 à 23 46 05

I get the same thing. The token is missing from their request:

Screen Shot 2021-06-20 at 3 38 42 PM

This is after the access ID and access Key is filled in.

@cgarrovillo
Copy link
Author

cgarrovillo commented Jun 20, 2021

Account Permissions:
1.Your cloud project on the Tuya IoT Platform was created after May 25, 2021.
2.On the Tuya IoT Platform, you have linked devices by using Tuya Smart or Smart Life app in your cloud project.
3.You entered the correct account and password of the Tuya Smart or Smart Life app in the Account and Password fields.

Please check this.

You guys keep referring to permissions, I don't see how this is a permissions issue at all. None of the error messages (that are unhandled btw) relate to missing or invalid information that I configure, so I assume this is a programming issue. How is access_token being calculated? Is this hashed internally? Why is it empty? Your documentation and videos all point to the config only requiring accessID and accessKey and NOT token.

Please look into the issue by reading the exceptions thrown, rather than assuming it is a user configuration error.

@Hanh94
Copy link
Contributor

Hanh94 commented Jun 21, 2021

Hello,

I tried to use this new plugin, but it doesn't work and i receive this message:

Capture d’écran, le 2021-06-18 à 23 46 05

My configuration of JASON file is:
Capture d’écran, le 2021-06-18 à 23 44 24

My configuration of Tuya Web Platform is:
Capture d’écran, le 2021-06-18 à 23 39 11
Capture d’écran, le 2021-06-18 à 23 40 49
Capture d’écran, le 2021-06-18 à 23 41 48

I use the same email address for my account of the cell apps and Web Platform but the password is different.

I'm absolutely sure that my credential is OK on JASON file. An idea why i receive this error message?

Thanks for your help!
Richard

Hi @rikray02 ,sorry for the bad experience.
Noticed that your project was created on April 20, 2021. Plugin requires that the project be created after May 25. Please create a new project, and then try again with the Access ID and Access Secret of the new project.

@Hanh94
Copy link
Contributor

Hanh94 commented Jun 21, 2021

documentation

Account Permissions:
1.Your cloud project on the Tuya IoT Platform was created after May 25, 2021.
2.On the Tuya IoT Platform, you have linked devices by using Tuya Smart or Smart Life app in your cloud project.
3.You entered the correct account and password of the Tuya Smart or Smart Life app in the Account and Password fields.
Please check this.

You guys keep referring to permissions, I don't see how this is a permissions issue at all. None of the error messages (that are unhandled btw) relate to missing or invalid information that I configure, so I assume this is a programming issue. How is access_token being calculated? Is this hashed internally? Why is it empty? Your documentation and videos all point to the config only requiring accessID and accessKey and NOT token.

Please look into the issue by reading the exceptions thrown, rather than assuming it is a user configuration error.

@Hanh94 Hanh94 closed this as completed Jun 21, 2021
@Hanh94 Hanh94 reopened this Jun 21, 2021
@Hanh94
Copy link
Contributor

Hanh94 commented Jun 21, 2021

Account Permissions:
1.Your cloud project on the Tuya IoT Platform was created after May 25, 2021.
2.On the Tuya IoT Platform, you have linked devices by using Tuya Smart or Smart Life app in your cloud project.
3.You entered the correct account and password of the Tuya Smart or Smart Life app in the Account and Password fields.
Please check this.

You guys keep referring to permissions, I don't see how this is a permissions issue at all. None of the error messages (that are unhandled btw) relate to missing or invalid information that I configure, so I assume this is a programming issue. How is access_token being calculated? Is this hashed internally? Why is it empty? Your documentation and videos all point to the config only requiring accessID and accessKey and NOT token.

Please look into the issue by reading the exceptions thrown, rather than assuming it is a user configuration error.

Hi @cgarrovillo ,Sorry for the bad experience.
Cloud interface needs to be authenticated by access_token in order to obtain the corresponding device information.

/v1.0/iot-01/associated-users/actions/authorized-login . This interface gets access_token, so it is correct that the access_token in the sign of this interface is "".

I've noticed that you're having trouble with the access_token request, and you get this error ‘access_token’ of ‘res.result’ as it is undefined when you request it. This is when you call this interface, you pass an invalid argument.

I see that your project creation time is in line with the requirements, and I believe that you are correct when config.json. There may be something wrong with the following link:
1.Smart Home PaaS API and Select Device Status Notification API.
2.Link devices by App Account > Add App Account.
3.Scan the QR code that appears using the Tuya Smart app or Smart Life app

@rikray02
Copy link

Hi Hanh94,
Thanks for your reply. Actually, i have a Trial Edition Cloud Project an i can't create more than 2 projects and i can't delete one of them or both. Bad news for me!!!! What can i do to fix this limitation or delete a projects?

Thanks again for your help.

@Hanh94
Copy link
Contributor

Hanh94 commented Jun 21, 2021

Hi Hanh94,
Thanks for your reply. Actually, i have a Trial Edition Cloud Project an i can't create more than 2 projects and i can't delete one of them or both. Bad news for me!!!! What can i do to fix this limitation or delete a projects?

Thanks again for your help.

If you have exceeded the limit of creating cloud project for free account (Only two projects), please create a new Tuya IoT Platform account and create the cloud project again.
If you want to use access ID and access Secret under your existing cloud account, please provide your cloud project's Authorization Key by creating a Technical ticket : https://service.console.tuya.com/8/2/list?source=content_feedback and we will modify it for you to make your cloud application available.
Hope this helps!

@moiz-z
Copy link

moiz-z commented Jun 22, 2021

Yeah, it's pretty terrible how this issue was handled. Anyway this is how you can fix it on your setup.

  1. Find where your node modules are and open up tuyashopenapi.js
  2. Under this.tokenInfo, update with the following:
this.tokenInfo = {

  access_token: '<this is the access secret on the project overview in your IoT project>',

  refresh_token: '', // leave this empty

  uid: '<get the uid from your linked devices by app account, the UID is for the actual device where you have the app, 
can be found under link devices on the second tab next to 'Project Overview'>',

  expire: 1653686505, // 1 year expiry
}
  1. Update this line of code in the same file under async _refreshAccessTokenIfNeed(path) to the following:
if ((this.tokenInfo.expire - 60) * 1000 > new Date().getTime()) {

    return;

  }

Restart homebridge.

Enjoy.

@rikray02 , see above

@kellemar
Copy link

Yeah, it's pretty terrible how this issue was handled. Anyway this is how you can fix it on your setup.

  1. Find where your node modules are and open up tuyashopenapi.js
  2. Under this.tokenInfo, update with the following:
this.tokenInfo = {

  access_token: '<this is the access secret on the project overview in your IoT project>',

  refresh_token: '', // leave this empty

  uid: '<get the uid from your linked devices by app account, the UID is for the actual device where you have the app, 
can be found under link devices on the second tab next to 'Project Overview'>',

  expire: 1653686505, // 1 year expiry
}
  1. Update this line of code in the same file under async _refreshAccessTokenIfNeed(path) to the following:
if ((this.tokenInfo.expire - 60) * 1000 > new Date().getTime()) {

    return;

  }

Restart homebridge.

Enjoy.

@rikray02 , see above

Just saw this. regarding editing the this.tokenInfo, which line did you edit it, since there are a few references to this in the same code.

I tried changing this in the constructor, and ended up with "Token Expired" error when it tried to fetch the device list.

@moiz-z
Copy link

moiz-z commented Jun 23, 2021

Just saw this. regarding editing the this.tokenInfo, which line did you edit it, since there are a few references to this in the same code.

I tried changing this in the constructor, and ended up with "Token Expired" error when it tried to fetch the device list.

It should be the first instance of this.tokenInfo in your file. For me it was around line 20.

If you are referring to the

if ((this.tokenInfo.expire - 60) * 1000 > new Date().getTime()) {

    return;

  }

This also is the first instance of this code, right after the previously mentioned code block. This code block on my text editor was on line 34.

@tcarr85
Copy link

tcarr85 commented Jun 24, 2021

Yeah, it's pretty terrible how this issue was handled. Anyway this is how you can fix it on your setup.

  1. Find where your node modules are and open up tuyashopenapi.js
  2. Under this.tokenInfo, update with the following:
this.tokenInfo = {

  access_token: '<this is the access secret on the project overview in your IoT project>',

  refresh_token: '', // leave this empty

  uid: '<get the uid from your linked devices by app account, the UID is for the actual device where you have the app, 
can be found under link devices on the second tab next to 'Project Overview'>',

  expire: 1653686505, // 1 year expiry
}
  1. Update this line of code in the same file under async _refreshAccessTokenIfNeed(path) to the following:
if ((this.tokenInfo.expire - 60) * 1000 > new Date().getTime()) {

    return;

  }

Restart homebridge.
Enjoy.
@rikray02 , see above

Just saw this. regarding editing the this.tokenInfo, which line did you edit it, since there are a few references to this in the same code.

I tried changing this in the constructor, and ended up with "Token Expired" error when it tried to fetch the device list.

I opened issue 41 and i attempted this process and this didn't work for me. It fixed the auth issue, but none of the devices are populating

@Hanh94 Hanh94 added code 1106 and removed question Further information is requested labels Jun 29, 2021
@Hanh94
Copy link
Contributor

Hanh94 commented Jul 1, 2021

Hi guys,,Sorry for the late reply.
Recently, our team has been sorting out interface issues such as code 2406, code 1106.
We will improve the plugin login experience as soon as possible.
Hope this doc has been helpful: https://developer.tuya.com/en/docs/iot/Tuya_Homebridge_Plugin?id=Kamcldj76lhzt. Any questions, please contact us.

@ElphaX
Copy link

ElphaX commented Jul 3, 2021

Let me know how you go Hanh, the emails I sent through have some visual aides if you need as well - here to help

@rikray02
Copy link

rikray02 commented Jul 9, 2021

Hi guys,
Sorry for a long period to test your suggest.
First of all, thank you all for your help. After trying everything (Create a new account in Tuya platform, create a new cloud Project, modify JS files, etc...), I still cannot get my accessories. I now have the same problem as Kellemar, "Token Expired".

I will therefore have a look at the ticket 41 side. Too bad it is so complicated to operate.
Richard

@cgarrovillo
Copy link
Author

Been hearing good things about tp-link's offerings so thats a better option actually

@Hanh94
Copy link
Contributor

Hanh94 commented Jul 9, 2021

Hi guys,
Sorry for a long period to test your suggest.
First of all, thank you all for your help. After trying everything (Create a new account in Tuya platform, create a new cloud Project, modify JS files, etc...), I still cannot get my accessories. I now have the same problem as Kellemar, "Token Expired".

I will therefore have a look at the ticket 41 side. Too bad it is so complicated to operate.
Richard

#41 (comment)

Yeah, it's pretty terrible how this issue was handled. Anyway this is how you can fix it on your setup.

  1. Find where your node modules are and open up tuyashopenapi.js
  2. Under this.tokenInfo, update with the following:
this.tokenInfo = {

  access_token: '<this is the access secret on the project overview in your IoT project>',

  refresh_token: '', // leave this empty

  uid: '<get the uid from your linked devices by app account, the UID is for the actual device where you have the app, 
can be found under link devices on the second tab next to 'Project Overview'>',

  expire: 1653686505, // 1 year expiry
}
  1. Update this line of code in the same file under async _refreshAccessTokenIfNeed(path) to the following:
if ((this.tokenInfo.expire - 60) * 1000 > new Date().getTime()) {

    return;

  }

Restart homebridge.
Enjoy.
@rikray02 , see above

Just saw this. regarding editing the this.tokenInfo, which line did you edit it, since there are a few references to this in the same code.
I tried changing this in the constructor, and ended up with "Token Expired" error when it tried to fetch the device list.

I opened issue 41 and i attempted this process and this didn't work for me. It fixed the auth issue, but none of the devices are populating

@Hanh94
Copy link
Contributor

Hanh94 commented Jul 9, 2021

Hi guys, Sorry for the bad experience.
We have optimized the README, please refer to the Error Code for login problems.

@Hanh94
Copy link
Contributor

Hanh94 commented Jul 27, 2021

Hi guys, For a better login experience, in version 1.3.0, the login interface is published in all regions. Therefore, you can use the endPoint of any region to log in. After a successful login, the endPoint of the region where the account resides is returned to obtain device information.
Any questions, please contact us.

@Hanh94
Copy link
Contributor

Hanh94 commented Aug 10, 2021

Hi guys, Since we haven't received your reply for a long time, we think our latest version should have solved your problem. We will close this issue first. If there is any problem, you can contact us at any time.

@Hanh94 Hanh94 closed this as completed Aug 10, 2021
@MarianLojka
Copy link

MarianLojka commented Aug 24, 2021

Hi,

I have completely same issue, I just installed plug-in 1.4. I tried to fix the issue with code mentioned here however after some time when everything worked fine I got expired token issue.

Any idea why doesn't work ?

@MarianLojka
Copy link

Hi, I solved it. The tricky point is the application account has to be registered only with region, which is supported by Tuya Cloud, which are listed at the wiki home down. I must to delete the app account and create new with new email with different region, I used Germany, then it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code 1106 good first issue This is a good issue for newcomers
Projects
None yet
Development

No branches or pull requests

8 participants