yo-han / Home-Assistant-Carelink

Unofficial Home Assistant Carelink Component
MIT License
19 stars 8 forks source link

Unable to configure using UI - cl_token and cl_refresh_token fields mapped incorrectly #76

Closed arandall closed 1 month ago

arandall commented 1 month ago

I tried to give this custom component a go to find that I would continually get a "Malformed access token" message in the log and an "Invalid authentication" message in the UI.

2024-03-24 05:58:06.176 DEBUG (MainThread) [custom_components.carelink.api] Carelink API: __execute_init_procedure()
2024-03-24 05:58:06.176 DEBUG (MainThread) [custom_components.carelink.api] Carelink API: _process_token_file()
2024-03-24 05:58:06.177 DEBUG (MainThread) [custom_components.carelink.api] Carelink API: _get_access_token_payload()
2024-03-24 05:58:06.177 DEBUG (MainThread) [custom_components.carelink.api] Carelink API: Malformed access token

Version: 491418666e52344b11e1745fc4302e19cf1619ca


Putting the following in the UI:

Screenshot_2024-03-24_18-02-38

I ended up with this logindata.json:

{
    "access_token": "refresh_token",
    "refresh_token": "access_token",
    "client_id": "client_id",
    "client_secret": "client_secret",
    "mag-identifier": "mag_identifier"
}

Looks like the parameters for the access and refresh tokens are swapped. A simple workaround is to enter the refresh token in the access token field and vice versa.

https://github.com/yo-han/Home-Assistant-Carelink/blob/491418666e52344b11e1745fc4302e19cf1619ca/custom_components/carelink/config_flow.py#L40-L47

https://github.com/yo-han/Home-Assistant-Carelink/blob/491418666e52344b11e1745fc4302e19cf1619ca/custom_components/carelink/api.py#L62-L70

yo-han commented 1 month ago

I made new release candidate with your pr and a few other fixes. Maybe you can test it too before we make this release public. It's working on my end but like to verify with at least one more user.

arandall commented 1 month ago

@yo-han I have tested 2024.3.1-rc1 and attempted to authenticate, everything works correctly.

Thank you!