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

Genesis EU / Login failed #514

Open
lmuser22 opened this issue Feb 24, 2024 · 12 comments
Open

Genesis EU / Login failed #514

lmuser22 opened this issue Feb 24, 2024 · 12 comments

Comments

@lmuser22
Copy link

Login in Germany / EU with Genesis fails

@cdnninja
Copy link
Collaborator

cdnninja commented Feb 24, 2024

Will need more details.

@lmuser22
Copy link
Author

image

and then
image

@lmuser22
Copy link
Author

image

@dmccaffery
Copy link

This seems to be an issue with the /signin invocation, which causes the /integrationinfo to fail. Also, the URL for the oidc auth endpoint should not include the /auth/ prefix.

Debug Logs

The _get_authorization_code_with_redirect_url fails:

024-05-01 12:14:09.349 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - Get Device ID request: https://prd-eu-ccapi.genesis.com:443/api/v1/spa/notifications/register {'ccsp-service-id': '3020afa2-30ff-412a-aa51-d28fbe901e10', 'ccsp-application-id': 'f11f2b86-e0e7-4851-90df-5600b01d8b70', 'Stamp': 'ImpZIJ2NNURLI0cNUotk8b8G05h70TJzbvXLirZ/QKkhptv+KoiKqNhaiBJUypM=', 'Content-Type': 'application/json;charset=UTF-8', 'Host': 'prd-eu-ccapi.genesis.com:443', 'Connection': 'Keep-Alive', 'Accept-Encoding': 'gzip', 'User-Agent': 'okhttp/3.12.0'} {'pushRegId': 'XXXXXX', 'pushType': 'GCM', 'uuid': 'XXXXX'}
2024-05-01 12:14:09.616 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - Get Device ID response: {'retCode': 'S', 'resCode': '0000', 'resMsg': {'deviceId': 'XXXXX'}, 'msgId': 'XXXXXX'}
2024-05-01 12:14:09.617 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - Get cookies request: https://prd-eu-ccapi.genesis.com:443/api/v1/user/oauth2/authorize?response_type=code&state=test&client_id=3020afa2-30ff-412a-aa51-d28fbe901e10&redirect_uri=https://prd-eu-ccapi.genesis.com:443/api/v1/user/oauth2/redirect&lang=en
2024-05-01 12:14:09.805 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - Get cookies response: {'account': 'XXXXX', 'TS01f622c7': 'XXXXX'}
2024-05-01 12:14:10.175 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - Sign In Response: {'errId': 'XXXXX', 'errCode': '4010', 'errMsg': 'Require authentication'}
2024-05-01 12:14:10.176 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - get_authorization_code_with_redirect_url failed

The fallback _get_authorization_code_with_form integrationinfo request also fails to return any values for userId and serviceId:

2024-05-01 12:14:10.358 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - IntegrationInfo Response: {'userId': '', 'serviceId': '', 'serviceName': ''}

Finally, the login form request fails (as the URL is incorrect and we get a 404):

2024-05-01 12:14:10.537 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - LoginForm https://accounts-eu.genesis.com/auth/realms/eugenesisidm/protocol/openid-connect/auth?client_id=3020afa2-30ff-412a-aa51-d28fbe901e10&scope=openid%20profile%20email%20phone&response_type=code&hkid_session_reset=true&redirect_uri=https://prd-eu-ccapi.genesis.com:443/api/v1/user/integration/redirect/login&ui_locales=en&state=: - Response: {"error":"HTTP 404 Not Found"}

This ultimately ends up with the exception in config_flow:

2024-05-01 12:14:10.542 ERROR (MainThread) [custom_components.kia_uvo.config_flow] Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 238, in login
    authorization_code = self._get_authorization_code_with_redirect_url(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1226, in _get_authorization_code_with_redirect_url
    parsed_url = urlparse(response["redirectUrl"])
                          ~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'redirectUrl'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/kia_uvo/config_flow.py", line 159, in async_step_user
    await validate_input(self.hass, user_input)
  File "/config/custom_components/kia_uvo/config_flow.py", line 63, in validate_input
    token: Token = await hass.async_add_executor_job(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 243, in login
    authorization_code = self._get_authorization_code_with_form(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1250, in _get_authorization_code_with_form
    login_form_action_url = soup.find("form")["action"].replace("&", "&")
                            ~~~~~~~~~~~~~~~~~^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

LoginForm URL

The login form URL used includes an /auth/ segment in the URL:

+ "/auth/realms/eugenesisidm/protocol/openid-connect/auth?client_id="

This should be:

     + "/realms/eugenesisidm/protocol/openid-connect/auth?client_id="

404 Error

curl -o /dev/null -s -w "\n%{http_code}\n" https://accounts-eu.genesis.com/auth/realms/eugenesisidm/protocol/openid-connect/auth

404

400 Error (I didn't submit client_id, etc)

curl -o /dev/null -s -w "\n%{http_code}\n" https://accounts-eu.genesis.com/realms/eugenesisidm/protocol/openid-connect/auth 

400

@cdnninja
Copy link
Collaborator

cdnninja commented May 1, 2024

Could you create a PR to solve it?

@dmccaffery
Copy link

Could you create a PR to solve it?

I am working through it, but even with the updated url I am now getting a Bad Request on the login form. I believe the issue may be that the https://prd-eu-ccapi.genesis.com:443/api/v1/user/integrationinfo endpoint is returning empty values for userId, serviceId, and serviceName. Is this API endpoint documented anywhere? I could not find anything on https://developers.genesis.com/web/v1/genesis/specification/account.

@cdnninja
Copy link
Collaborator

cdnninja commented May 2, 2024

No. Reverse engineering the native app is the only way.

@pasqualito79
Copy link

any updates on this issue? This is also not working:
https://prd-eu-ccapi.genesis.com/api/v1/user/oauth2/authorize?response_type=code&state=test&client_id=3020afa2-30ff-412a-aa51-d28fbe901e10&redirect_uri=https://prd-eu-ccapi.genesis.com/api/v1/user/oauth2/redirect

{"errId":"fe69c315-9b0f-49d7-8c16-778b9b33ea87","errCode":"4002","errMsg":"Invalid parameters"}

@pasqualito79
Copy link

pasqualito79 commented May 13, 2024

@pasqualito79
Copy link

pasqualito79 commented May 13, 2024

I'm nearly there...Setting Language and Login works (Language of push requests were changed after that):

https://prd-eu-ccapi.genesis.com/api/v1/user/language
 {"lang":"de"}
https://prd-eu-ccapi.genesis.com/api/v1/user/signin
{"email":"***","password":"***"}
--
{"step":4,"upgrade":false}

after that, this is also wrong:

https://prd-eu-ccapi.genesis.com/api/v1/user/oauth2/token

code=&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fprd-eu-ccapi.genesis.com%2Fapi%2Fv1%2Fuser%2Foauth2%2Fredirect
--
{"errId":"a0dc915f-bfe8-4b7e-afad-45a385cb3b15","errCode":"4002","errMsg":"Invalid parameters"}

should be:

https://prd-eu-ccapi.genesis.com/api/v1/user/oauth2/token

client_id=3020afa2-30ff-412a-aa51-d28fbe901e10&code=***&grant_type=authorization_code&redirect_uri=https%3A//accounts-eu.genesis.com/realms/eugenesisidm/ga-api/redirect2

hope this helps!

@cdnninja
Copy link
Collaborator

Could you create a PR for this?

@pasqualito79
Copy link

Sorry, I'm not really a developer, I just tried to read your code because I'm interested in getting this API running. I've a Genesis car and also know how to use a proxy to be able to catch all the requests and responses from the Genesis iOS app. So if you need any info or testing of the Genesis app / API I'm here to help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants