ewelink-api icon indicating copy to clipboard operation
ewelink-api copied to clipboard

Error 401: Wrong account or password -- again

Open nareso opened this issue 2 years ago • 54 comments

I got an Error 401 same as #212 today. https://github.com/skydiver/ewelink-api/issues/212

This error does not occur with sonoff devices but occurs with 4ch products that have the PSF-B04 module when using setDevicePowerState methods.

Is there anyone with the same symptoms?

nareso avatar Aug 10 '23 04:08 nareso

Correction, sonoff devices also become errors.

nareso avatar Aug 10 '23 06:08 nareso

I found a temporary workaround.

APP_ID: Uw83EKZFxdif7XFXEsrpduz5YyjP7nTl APP_SECRET: mXLOjea0woSMvK9gw7Fjsy7YlFO4iSu6 works for me.

Thanks, LiorLindvor. https://github.com/skydiver/ewelink-api/issues/212#issuecomment-1485629138

nareso avatar Aug 10 '23 07:08 nareso

after registering your ewelink account and creating app, did your app_id and secret_id work normally?

evergreen165 avatar Aug 11 '23 17:08 evergreen165

I've had little problem finding correct directory under my portainer node-red install, found here: //data/node_modules/ewelink-api/src/data$ -if anyone has same problem. Using vi editor I have changed the credentials as above (or create your own under dev.ewelink.cc) and the auth problem solved now!

karocavo avatar Aug 12 '23 19:08 karocavo

@antonioGabrielGomes , all, I've created my own APP_ID & APP_SECRET on dev.ewelink.cc, - standard role. However this doens't fully work. I can get devices and events just fine, but all other nodes just give me "wrong account or password".

With the above credentials from @nareso , I get full functionality. At this point, should I assume the issue is with the role?

mduchain avatar Aug 13 '23 10:08 mduchain

@karocavo

I did that but got the same error

evergreen165 avatar Aug 13 '23 14:08 evergreen165

@mduchain

It could be the type of account we're creating, maybe individual developer access doesn't have permissions.

evergreen165 avatar Aug 13 '23 14:08 evergreen165

Regarding authorization issues, accounts created by individual developers can only be redirected to the authorization page for login. So it cannot directly request the login interface to obtain a Token, the specific information is here: https://coolkit-technologies.github.io/eWeLink-API/#/en/OAuth2.0

ghost avatar Aug 14 '23 06:08 ghost

Hi carl , thanks for your reply.

I do not understand the Create application procedure, but how should I describe it in the redirect URL field?

By the way, in my account, I can login with https://dev.ewelink.cc/#/login, but with https://c2ccdn.coolkit.cc/oauth/index.html the login process does not proceed.

nareso avatar Aug 14 '23 07:08 nareso

This is an example of eWeLink OAuth2.0 login:https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo

ghost avatar Aug 14 '23 09:08 ghost

Hi carl, thank you very much for your kind explanation.

But, I can't find config.js in ewelink-api directory. Isn't your example for ewelink-api-next?

Please tell me the create application procedure when using ewelink-api.

nareso avatar Aug 14 '23 10:08 nareso

Hi carl, thank you very much for your kind explanation.

But, I can't find config.js in ewelink-api directory. Isn't your example for ewelink-api-next?

Please tell me the create application procedure when using ewelink-api.

The file to overwrite keys from previous comments is in directory path i’ve mentioned specifically in case of a portainer install (NAS)- keys from ewelink.cc supposedly do not work, as written above

karocavo avatar Aug 14 '23 10:08 karocavo

Hi carl , thanks for your reply.

I do not understand the Create application procedure, but how should I describe it in the redirect URL field?

By the way, in my account, I can login with https://dev.ewelink.cc/#/login, but with https://c2ccdn.coolkit.cc/oauth/index.html the login process does not proceed.

the same here.

evergreen165 avatar Aug 14 '23 12:08 evergreen165

Well, I've had problems with Error 401, now it's gone. I have not created API myself, but used keys from this post - APP_ID: Uw83EKZFxdif7XFXEsrpduz5YyjP7nTl APP_SECRET: mXLOjea0woSMvK9gw7Fjsy7YlFO4iSu6 /by nareso/ and changed these in settings.js file under command line in nodered container - attached pic for reference nr2

karocavo avatar Aug 14 '23 12:08 karocavo

Regarding authorization issues, accounts created by individual developers can only be redirected to the authorization page for login. So it cannot directly request the login interface to obtain a Token, the specific information is here: https://coolkit-technologies.github.io/eWeLink-API/#/en/OAuth2.0

Thanks for the info. Now, with the individual developer method, we can integrate with devices ? making a boost on the demo you sent?

evergreen165 avatar Aug 14 '23 13:08 evergreen165

Uw83EKZFxdif7XFXEsrpduz5YyjP7nTl It is an APPID that should not be used, please ignore it.

Through personal developer methods, it is possible to integrate with devices. I will add an example of obtaining device information and controlling devices later, but the specific content needs to be configured based on your device.

ghost avatar Aug 15 '23 01:08 ghost

Updated, feat: Add device examples to control the current login account https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo

ghost avatar Aug 15 '23 08:08 ghost

@coolkit-carl can we say at least that it is really messy ?? Why Ewelink disables v1 interface while v2 interface does not work for production ?

On my side, my own app_id and app_secret doesn't work but this app_id works : Uw83EKZFxdif7XFXEsrpduz5YyjP7nTl Which is really weird.

Can you explain us how to easily use your ewelink-api-next to basically turn on/off a device please ?

Documentation here : https://coolkit-technologies.github.io/eWeLink-API/#/en/OAuth2.0 Or here : https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo are clearly not understandable and seems to not be stable at all.

thomas350 avatar Aug 16 '23 11:08 thomas350

  1. Can you give an example of why you feel unstable? The v2 interface has been running and maintained for 3 years, and there have been no significant changes to the interface.
  2. We have stopped maintaining the v1 interface. Its security is not as high as the v2 interface, and its functionality is not as comprehensive as the v2 interface. Stopping is inevitable. 3 https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo <https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo > I updated the latest document for this project yesterday and wrote about the entire process.
  3. ewelink-api-next actually has basic examples. In the next few days, it will be open source and provide additional documentation for all functions (in fact, if you use TypeStript, you will get a more perfect prompt, and its source code also has annotations). Dep:产品部|解决方案工程师 Name:刘家乐 @.*** @.*** > Tel:+86(0)755 26404901 Mob:+86 18598029557

发件人:thomas350 @.> 发送时间:2023年8月16日(星期三) 19:48 收件人:skydiver/ewelink-api @.> 抄 送:刘家乐 @.>; Mention @.> 主 题:Re: [skydiver/ewelink-api] Error 401: Wrong account or password -- again (Issue #220) @coolkit-carl <https://github.com/coolkit-carl > can we say at least that it is really messy ?? Why Ewelink is disabling v1 interface while v2 interface does not work for production ? On my side, my own app_id and app_secret doesn't work but this app_id works : Uw83EKZFxdif7XFXEsrpduz5YyjP7nTl Which is really weird. Can you explain us how to easily use your ewelink-api-next to basically turn on/off a device please ? Documentation here : https://coolkit-technologies.github.io/eWeLink-API/#/en/OAuth2.0 <https://coolkit-technologies.github.io/eWeLink-API/#/en/OAuth2.0 > Or here : https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo <https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo > are clearly not understandable and seems to not be stable at all. — Reply to this email directly, view it on GitHub <https://github.com/skydiver/ewelink-api/issues/220#issuecomment-1680456963 >, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AMDDIXVSHSAIYH2XMKDTXDTXVSXRZANCNFSM6AAAAAA3K5OG2Q >. You are receiving this because you were mentioned.Message ID: @.***>

ghost avatar Aug 17 '23 01:08 ghost

  1. Can you give an example of why you feel unstable? The v2 interface has been running and maintained for 3 years, and there have been no significant changes to the interface. 2. We have stopped maintaining the v1 interface. Its security is not as high as the v2 interface, and its functionality is not as comprehensive as the v2 interface. Stopping is inevitable. 3 https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo <https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo > I updated the latest document for this project yesterday and wrote about the entire process. 4. ewelink-api-next actually has basic examples. In the next few days, it will be open source and provide additional documentation for all functions (in fact, if you use TypeStript, you will get a more perfect prompt, and its source code also has annotations). Dep:产品部|解决方案工程师 Name:刘家乐 @.*** @.*** > Tel:+86(0)755 26404901 Mob:+86 18598029557 ------------------------------------------------------------------ 发件人:thomas350 @.> 发送时间:2023年8月16日(星期三) 19:48 收件人:skydiver/ewelink-api @.> 抄 送:刘家乐 @.>; Mention @.> 主 题:Re: [skydiver/ewelink-api] Error 401: Wrong account or password -- again (Issue #220) @coolkit-carl <https://github.com/coolkit-carl > can we say at least that it is really messy ?? Why Ewelink is disabling v1 interface while v2 interface does not work for production ? On my side, my own app_id and app_secret doesn't work but this app_id works : Uw83EKZFxdif7XFXEsrpduz5YyjP7nTl Which is really weird. Can you explain us how to easily use your ewelink-api-next to basically turn on/off a device please ? Documentation here : https://coolkit-technologies.github.io/eWeLink-API/#/en/OAuth2.0 <https://coolkit-technologies.github.io/eWeLink-API/#/en/OAuth2.0 > Or here : https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo <https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo > are clearly not understandable and seems to not be stable at all. — Reply to this email directly, view it on GitHub <#220 (comment) >, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AMDDIXVSHSAIYH2XMKDTXDTXVSXRZANCNFSM6AAAAAA3K5OG2Q >. You are receiving this because you were mentioned.Message ID: @.***>

Does the method in the demo not work for 4ch devices? and does the library work to enable and disable devices in real time?

evergreen165 avatar Aug 17 '23 12:08 evergreen165

  1. For 4ch devices, the control instructions are different and the method is the same. Change {"switch": "on"} to {"switches": [{"switch": "off", "outlet": 0}, {"switch": "off", "outlet": 1}, {"switch": "off", "outlet": 2}, {"switch": "off", "outlet": 3}]} to complete this section https://coolkit-technologies.github.io/eWeLink-API/#/en/UIIDProtocol It is stated in the document.

  2. It supports real-time control of devices, whether through interfaces or websockets.

ghost avatar Aug 18 '23 02:08 ghost

Hi carl

I noticed that the object structure has changed between V1 and V2. For example, an ”off” information of a single switch from node-red-contrib-ewelink are V1 --- msg.payload.params.switch: "off" V2 --- msg.payload.params.switch.switch: "off" Like, it's one layer deep.

Could these changes be the reason that node-red-contrib-ewelink doesn't work properly with V2 interfaces?

nareso avatar Aug 18 '23 06:08 nareso

No, the action for controlling the device have not changed. We have only changed the interface domain name, path, and parameter transfer method.

ghost avatar Aug 18 '23 06:08 ghost

The change from V1 object {"switch":"off"} to V2 object {"switch":{"switch":"off"}} is a very big change for me.

To which of the described changes does such a change apply?

nareso avatar Aug 18 '23 08:08 nareso

There is no change, {"switch": {"switch": "off"}} is incorrect.

ghost avatar Aug 18 '23 08:08 ghost

Here is my environment and results.

Nod-red version : v3.0.2 node-red-contrib-ewelink version : 2.0.0 node: ewelink-generic-device input : {"method":"getDevice"}

Using V1 API output path of "off" is msg.payload.params.switch: "off"

Using V2 API output path of "off" is msg.payload.params.switch.switch: "off"

please confirm.

nareso avatar Aug 18 '23 09:08 nareso

@coolkit-carl

Can you explain us how to easily use your ewelink-api-next to basically turn on/off a 4ch device please ?

Documentation here : https://coolkit-technologies.github.io/eWeLink-API/#/en/OAuth2.0 Or here : https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo are clearly not understandable and doesn't have example.

Thank you.

thomas350 avatar Aug 18 '23 13:08 thomas350

Ok I have this working for my hallway 2 channel light switch. I can turn them on and off right now.

in plain English:

  1. Learn what OAuth is... or follow the instructions at https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo to run a local web server and login - after that you will be redirected back to your redirectUrl and a token.json will be saved with your authentication tokens. Keep this safe!

  2. run controlDeviceDemo.js - this listed all my devices... that was good, but the code to toggle the first device as a demo did not work for me... but having the list of devices showed that I was authenticated correctly.

  3. By trial and error I worked out then that I could pass the following code

await client.device.setThingStatus({
          type: 1,
          id: '10007bc171', // not my real id, but I used my real id here
          params:
            {
              "switches": [
                {"switch": "on", "outlet": 0},
                {"switch": "on", "outlet": 1}
              ]
            }
        })

AND MY LIGHTS TURNED ON....

  1. with some playing I was able to dump the actual HTTP request that was being made, which simply looks like (This is not code that you can copy and paste from this comment to make it work, this is a dump of the request for you to look at, and to compile your own HTTP Request that looks like this - any decent developer should be able to make a HTTP request in their programming language of choice)
Send request:  {
  url: '/v2/device/thing/status',
  method: 'post',
  baseURL: 'https://eu-apia.coolkit.cc',
  headers: AxiosHeaders {
    Accept: 'application/json, text/plain, */*',
    'Content-Type': 'application/json',
    Authorization: 'Bearer aa0dbbf06cd1NOTMYREALKEY8e84f9a09ffe536d62',
    'X-CK-Nonce': '4s3p08wn',
    Date: '1692398015055'
  },
  params: undefined,
  data: '{"type":1,"id":"10007bc171","params":{"switches":[{"switch":"off","outlet":0},{"switch":"off","outlet":1}]}}'
}

So now I have a proof of concept working in Javascript, I can switch back to PHP and write real HTTP requests, that consume the OAuth Endpoint, which gives me a token to store, and then I can then just use any HTTP client (mine will continue to be PHP) to make http requests

Once you have an access token from OAuth you can call any of the APIs - here is a scaled down request, made by standard curl command

curl --location 'https://eu-apia.coolkit.cc/v2/device/thing/status' \
--header 'X-CK-Nonce: 9e3NOTREALwR7' \
--header 'Authorization: Bearer 90e4e9c7de5NOTMYREALTOKENd36154e3bbc2' \
--header 'Content-Type: application/json' \
--data '{
    "type": 1,
    "id": "10007bc171",
    "params": {
        "switches": [
                {"switch": "on", "outlet": 1}
              ]
    }
}'

The above all works in real life in my house today. Im not @coolkit-carl, Im a PHP dev with API experience :)

If you are looking for a non-technical project where you can just input your username and password to a config file, and magically control your devices, then you can no longer do that. But if you are willing to learn basic development (like OAuth which is pretty much industry standard for authenticating and authorising external services nowadays) then that can be "easily" done.

The old ewelink-api project should be considered deprecated and no longer used.

PhilETaylor avatar Aug 18 '23 22:08 PhilETaylor

I will also just note that the OAuth 2.0 process they are using is crazy and non-standard. If it were standard OAuth then tools like PostMan would be able to get access tokens automatically.

The Authorisation parameters are simply wrong for standard OAuth -https://coolkit-technologies.github.io/eWeLink-API/#/en/OAuth2.0?id=authorization-page-description (eg client_id is right clientId is non-standard etc.)

The PostMan Collection/Environment provided as an example (https://coolkit-technologies.github.io/eWeLink-API/#/en/APICenterV2?id=postman-example), doesnt even support auto Oauth2.0 to get a bearer token :( so at the moment the only way to get/refresh your token is with the demo app that was provided as an example https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo - or to hand code your OAuth authorisation signature as per the documentation on how to hash the authorisation signatures.

PhilETaylor avatar Aug 18 '23 23:08 PhilETaylor

Thank you for your detailed explanation.

Now, when the V1 interface is deprecated, I would like an alternative environment for ewelink-api, but if anyone knows a recommended environment, please let me know.

Development candidates that can control ewelink device with low code are

  1. node-red-contrib-ewelink-cube In my testing, it's still unstable.
  2. Homeassiatant Add-on eWeLink Smart Home Does this use the V2 interface?
  3. homebridge-ewelink Does this use the V2 interface?
  4. other candidates

Any comments would be appreciated.

nareso avatar Aug 21 '23 02:08 nareso