guerrerotook / securitas-direct-new-api

This repository contains the new securitas direct API that can be integrated in Home Assistant
Apache License 2.0
73 stars 30 forks source link

Unknown Error after entering OTP #194

Closed jlg78fr closed 6 months ago

jlg78fr commented 6 months ago

Hi

When setting up the app in HA, when I enter the OTP received from Securitas, I get an "unknown error" (see attached screenshot and journal error files). I can log into the internet app at https://customers.securitasdirect.fr/owa-static/login with no problem.

Thanks for any help/suggestions Jean

securitas_2.txt securitas_1.txt Capture d’écran 2024-01-11 173358

ismael-onoro commented 6 months ago

Exactly same issue here. Hoping for some support.

guerrerotook commented 6 months ago

The only relevant information that I found is this:

Merci de vous déconnecter et de vous connecter à nouveau à l'application

Why don't you try to log out and log in again?

jlg78fr commented 6 months ago

Hi I tried several times... I also logged out of the app on my phone I also tried uninstalling and reinstalling, no success I can log in on the internet and the app on my phonew/o any problem

guerrerotook commented 6 months ago

I see, we have other users from France using the integration. Are you using your main user or a different one?

jlg78fr commented 6 months ago

The main user Trying to install with secondary user shows "Unknown error occurred" on login screen I found also another user with the same issue in the HC forum https://community.home-assistant.io/t/securitas-direct-verisure-eu-custom-component-testers-wanted/70239/415 Thanks

cantupaz commented 6 months ago

I suspect Securitas changed the API. But perhaps only in France? Where the logs from @jlg78fr show "{'auth-type': 'OTP', 'auth-code': '100029'}", mine show the rest of the data needed to complete the authorization...

I guess they will break the API in Spain soon, but until then I'm not sure I know how to fix this.

"data": { "auth-type": "OTP", "auth-code": "10001", "auth-phones": [ { "id": 0, "phone": "**903" },.... ], "auth-otp-hash": "e12130e4-17f2-400e-b38c-9aXXXXXXX" },

cantupaz commented 6 months ago

actually I thought about it last night and remembered that a couple of weeks ago I found out that the 2FA step doesn't seem to do anything useful behind the scenes. So... I'll be sending @guerrerotook a pull request to make the 2FA steps optional and maybe that will help. Stay tuned.

guerrerotook commented 6 months ago

That confused me a little bit, what do you mean the 2FA doesn't do anything? Is this not part of the configuration flow?

cantupaz commented 6 months ago

it is part of the configuration flow, but it doesn't do anything useful. At the end of the flow with 2FA you get a token :

line 252 of apimanager.py: self.authentication_token = response["data"]["xSValidateDevice"]["hash"]

which is the exact same token you get after login() 324: self.authentication_token = response["data"]["xSLoginToken"]["hash"]

I figured this out when I refactored the api manager into its own library and made a little example script that simply does not call the 2FA functions. The script only uses login and just works. Try running that script outside of HA and see (you may have to play with the path).

cantupaz commented 6 months ago

@jlg78fr Does it work now? You'd have to use the latest release. When you configure the integration, in the window that asks for your username/password you should see an unchecked box next to "Use 2FA". Leave the box unchecked and try.

jlg78fr commented 6 months ago

Hi @cantupaz Latest release is still 2.6.0.0 As soon as the new release is available, I will try it. Thanks for your help. Jean

jlg78fr commented 6 months ago

Hi @cantupaz I downloaded the code and copied it to my HA securitas directory. When I leave the blank checkbox unchecked, I get an "unknown error occurred" message.

Capture d’écran 2024-01-21 104417

Thanks Jean

cantupaz commented 6 months ago

hmmm,a blank checkbox. Sorry. I introduced a bug, which I think I fixed yesterday while I was adding support for perimetral alarms. I just opened a PR to integrate that. If you're comfortable try downloading the code from https://github.com/cantupaz/securitas-direct-new-api if you still see an issue, please add the logs here so I can take a look.

jlg78fr commented 6 months ago

HI @cantupaz Now 2 blank check boxes...and still the same error leaving both unchecked Logs attached

Capture d’écran 2024-01-21 163500 securitas-3.txt

jlg78fr commented 6 months ago

And when I check the first blank box and after entering the OTPreceived from Securitas, same error see attached log securitas-5.txt

cantupaz commented 6 months ago

I’ll take a look tomorrow. One question in the mean time: Did you delete the integration before copying the code? So 1. Delete the existing integration 2. Copy the code (the directory should have been deleted from custom_components 3. Restart HAErickSent from a small keyboardOn Jan 21, 2024, at 5:17 PM, jlg78fr @.***> wrote: And when I check the first blank box and after entering the OTPreceived from Securitas, same error see attached log securitas-5.txt

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

jlg78fr commented 6 months ago

Hi, yes I deleted completely the old integration and copied the new one from your repository and restarted HA.

cantupaz commented 6 months ago

I've been looking at this but I am totally stumped.

I don't think this is related to 2FA at all since you get the same results with and without the 2FA code. I'll keep thinking about what to do.

jlg78fr commented 6 months ago

Hi @cantupaz

Checking the logs I notice that my installation number is wrong, it should be 012345 and not 12345 FYI my username is 0012345 (example of course :)) see attached last line of log

securitas-5.txt

I don't know if this is the source of the error Thanks Jean

cantupaz commented 6 months ago

I don't know if that's the source of the error, but I made some code changes if you want to try reinstalling from my repo https://github.com/cantupaz/securitas-direct-new-api

jlg78fr commented 6 months ago

@cantupaz Many Thanks, this was the cause of the error, and the code now works perfectly (I used OTP to setup) Can you please forward your changes to @guerrerotook ? Again, thank you both for your help and support Jean

cantupaz commented 6 months ago

Great. The code changes were in last night's merge, so they should go out in the next release.