bretterer / home-assistant-rivian

Rivian (Unofficial) Integration for Home Assistant
Apache License 2.0
125 stars 20 forks source link

Setup integration: unknown error on login #173

Closed InnerSphere closed 3 months ago

InnerSphere commented 3 months ago

On a fresh install of home assistant and HACS, attempting to add the integration results in an "Unknown error occurred" message when submitting login credentials.

Replication steps:

  1. Linux home assistant VirtualBox image installed
  2. HACS installed using the OS/Supervised script; reboot
  3. Add Rivian (Unofficial) bretterer/home-assistant-rivian (integration) repository to HACS; reboot
  4. Settings > Devices & Services > Add Integration > Rivian (Unofficial)
  5. Prompted for username and password at Setup your Rivian Integration
  6. Unknown error occurred message

Edit: attempted multiple confirmed usernames paired to vehicle.

image

Home Assistant Core 2024.8.1 Supervisor 2024.08.0 Operating System 12.4 Frontend 20240809.0

Home Assistant Community Store Integration version: 1.34.0 Frontend version: 20240119163101 Repositories: 1390 Downloaded repositories: 2

natekspencer commented 3 months ago

Please enable debug logs, attempt to sign in again, then post the debug logs for further assistance. Without, it's impossible to tell what might be going on.

InnerSphere commented 3 months ago

@natekspencer

edit: redacted token info below

Logger: aiohttp.server Source: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:428 First occurred: 5:53:23 PM (1 occurrences) Last logged: 5:53:23 PM

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 459, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle result = await handler(request, request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin return await func(self, request, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post return await super().post(request, flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper return await method(view, request, data, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post result = await self._flow_mgr.async_configure(flow_id, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 366, in async_configure result = await self._async_configure(flow_id, user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 413, in _async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step result: _FlowResultT = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/rivian/config_flow.py", line 252, in async_step_user await self._rivian.authenticate(username, password) File "/usr/local/lib/python3.12/site-packages/rivian/rivian.py", line 165, in authenticate response = await self.graphql_query(headers, url, graphql_json) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/rivian/rivian.py", line 688, in graphql_query raise exception File "/usr/local/lib/python3.12/site-packages/rivian/rivian.py", line 679, in graphql_query raise err_cls(response.status, response_json, headers, body) rivian.exceptions.RivianBadRequestError: (200, {'errors': [{'extensions': {'code': 'BAD_REQUEST_ERROR', 'reason': 'REST_FORBIDDEN'}, 'message': 'Bad request error', 'path': ['login']}], 'data': None}, {'User-Agent': 'RivianApp/707 CFNetwork/1237 Darwin/20.4.0', 'Accept': 'application/json', 'Content-Type': 'application/json', 'Apollographql-Client-Name': 'com.rivian.ios.consumer-apollo-ios', 'Csrf-Token': 'tokenhere', 'A-Sess': 'sessionhere', 'Dc-Cid': 'm-ios-b08e7649-f1b0-4d31-86cf-a36595c4460c'}, {'operationName': 'Login', 'query': 'mutation Login($email: String!, $password: String!) {\n login(email: $email, password: $password) {\n typename\n ... on MobileLoginResponse {\n typename\n accessToken\n refreshToken\n userSessionToken\n }\n ... on MobileMFALoginResponse {\n typename\n otpToken\n }\n }\n}', 'variables': {'email': 'emailhere', 'password': 'passwordhere'}})

natekspencer commented 3 months ago

Thanks, do you have any weird characters in your password maybe? It looks like you are getting to the Rivian api just fine, but you're getting a response back saying the request was bad. Could you also verify which version of HA you are running as well as the version of this integration, just to rule those out?

natekspencer commented 3 months ago

And also, can you attempt to log in to the Rivian app/website with the username/password you are trying for this integration, just to rule that out too.

InnerSphere commented 3 months ago

@natekspencer

Home Assistant Core 2024.8.1 Supervisor 2024.08.0 Operating System 12.4 Frontend 20240809.0

Home Assistant Community Store Integration version: 1.34.0 Frontend version: 20240119163101

Home Assistant integration for Rivian (Unofficial) GitHub Release v1.3.1

Changed password to alphanumeric only to rule out special characters but still receive same error on HA side.

Confirmed can log into the Rivian website directly with two different accounts. I can see the successful GraphQL request payload and response for OTP in the Chromium dev tools.

{
  "query": "\n  mutation login($credentials: CredentialsInput!) {\n    login(credentials: $credentials) {\n      \n  userId\n  firstName\n  lastName\n  email {\n    id\n    email\n  }\n  urls\n  localizationPreferences {\n    language\n  }\n  \n  orderSearchResults (input:{ orderTypes: [PRE_ORDER, VEHICLE, RETAIL], pageInfo: { size: 250, from: 0} }) {\n    total\n    data {\n      id\n      total\n      paidTotal\n      subtotal\n      state\n      configurationStatus\n      currency\n      orderDate\n      type\n      fulfillmentSummaryStatus\n      orderConfirmationType\n      vehicleId\n      invitedToSelfConfirm\n      invitedToSelfConfigure\n      eligibleForNewVehicleInventoryMarketplace\n      metadata {\n        discounts {\n          items {\n            discountType\n            title\n            amount\n            percentage\n          }\n        }\n      }\n      refundableAmount {\n        reason\n      }\n      urls\n      items{\n        id\n        total\n        unitPrice\n        quantity\n        type\n        estimatedDeliveryWindow {\n      endDate\n      startDate\n    }\n        discounts {\n          items {\n            discountType\n            code\n            title\n            amount\n          }\n          postTax\n          preTax\n          total\n        }\n        shippingAddress {\n          line1\n          line2\n          city\n          state\n          country\n          postalCode\n        }\n        productDetails{\n          ... on IItemProduct {\n            sku\n            productCode\n            store {\n              country\n            }\n          }\n        }\n        configuration{\n          basePrice\n          ruleset{\n            meta{\n              locale\n              currency\n              country\n              vehicle\n              version\n            }\n            groups\n            rules\n            specs\n            options\n          }\n          options{\n            optionId\n            groupId\n            price\n            optionDetails {\n              name\n              fullName\n              attrs\n              price\n              visualExterior\n              visualInterior\n            }\n          }\n        }\n      }\n    }\n  }  \n\n  vehicles {\n  id\n  model\n  highestPriorityRole\n  vin\n}\n  invites (filterStates: [PENDING]) {\n  id\n  inviteState\n  vehicleModel\n  vehicleId\n  creatorFirstName\n}\n\n    }\n  }\n",
  "variables": {
    "credentials": {
      "email": "***emailhere***",
      "password": "***passwordhere***"
    }
  }
}

{
    "query": "\nmutation loginWithOTP($credentials: OTPCredentialsInput!) {\n  loginWithOTP(credentials: $credentials) {\n    \n  userId\n  firstName\n  lastName\n  email {\n    id\n    email\n  }\n  urls\n  localizationPreferences {\n    language\n  }\n  \n  orderSearchResults (input:{ orderTypes: [PRE_ORDER, VEHICLE, RETAIL], pageInfo: { size: 250, from: 0} }) {\n    total\n    data {\n      id\n      total\n      paidTotal\n      subtotal\n      state\n      configurationStatus\n      currency\n      orderDate\n      type\n      fulfillmentSummaryStatus\n      orderConfirmationType\n      vehicleId\n      invitedToSelfConfirm\n      invitedToSelfConfigure\n      eligibleForNewVehicleInventoryMarketplace\n      metadata {\n        discounts {\n          items {\n            discountType\n            title\n            amount\n            percentage\n          }\n        }\n      }\n      refundableAmount {\n        reason\n      }\n      urls\n      items{\n        id\n        total\n        unitPrice\n        quantity\n        type\n        estimatedDeliveryWindow {\n      endDate\n      startDate\n    }\n        discounts {\n          items {\n            discountType\n            code\n            title\n            amount\n          }\n          postTax\n          preTax\n          total\n        }\n        shippingAddress {\n          line1\n          line2\n          city\n          state\n          country\n          postalCode\n        }\n        productDetails{\n          ... on IItemProduct {\n            sku\n            productCode\n            store {\n              country\n            }\n          }\n        }\n        configuration{\n          basePrice\n          ruleset{\n            meta{\n              locale\n              currency\n              country\n              vehicle\n              version\n            }\n            groups\n            rules\n            specs\n            options\n          }\n          options{\n            optionId\n            groupId\n            price\n            optionDetails {\n              name\n              fullName\n              attrs\n              price\n              visualExterior\n              visualInterior\n            }\n          }\n        }\n      }\n    }\n  }  \n\n  vehicles {\n  id\n  model\n  highestPriorityRole\n  vin\n}\n  invites (filterStates: [PENDING]) {\n  id\n  inviteState\n  vehicleModel\n  vehicleId\n  creatorFirstName\n}\n\n  }\n}\n",
    "variables": {
        "credentials": {
            "sessionToken": "***token string here***",
            "email": "***email here***",
            "otpToken": "***sms otp here***"
        }
    }
}
natekspencer commented 3 months ago

Just spitballing here since I can't see anything wrong thus far and was also able to log in successfully with two different accounts, both with and without 2fa enabled, so I've so far been unable to reproduce.

Do you have a vehicle associated with your accounts already, not just an order? The website uses a slightly different endpoint to login (orders/graphql instead of gateway/graphql).

natekspencer commented 3 months ago

Also, can you verify a successful login via the mobile apps, not just web? (Trying to cover everything)

tmack8001 commented 3 months ago

Could you also confirm if when you login via either the web or mobile that you aren't faced with a reCaptcha login verification prompt?

InnerSphere commented 3 months ago

@natekspencer @tmack8001

Looks like logging into the iOS app is OK without a captcha. I considered if there was a change with the recent update of connect+ but afaik it has not rolled out yet.

Tried disabling IPv6 and removing/reinstalling the integration but still received the same BAD_REQUEST_ERROR.

Vehicle looks OK on the app and receiving updates on charging status.

image

tmack8001 commented 3 months ago

@InnerSphere I know it may sound strange, but could you try to login with HA again today.

There are some reports I'm seeing in the 3P API space for Rivian were last night there was a regression in the cloud servers (higher error rate and general slowness observed). See if today things are better for you.

InnerSphere commented 3 months ago

@tmack8001 Must have been a problem on Rivian's end after all. Able to use the integration normally today. Thank you all for your insights on this.

cowboyrushforth commented 3 months ago

Just setting up the integration for the first time. Have the exact stack trace as above. Is Rivian having issues again? Website and iPhone app work great. No strange characters in email or password. Sorry to bother if this is totally outside of the scope of this project. Thanks!

tmack8001 commented 3 months ago

I've seen reports in the community about some authentication failures today, yes this does seem to be something within the Rivian side of things.

ChadMoran commented 3 months ago

Can confirm this is happening to me.