Skip to content

MyUplink driver uses unsupported client_credentials OAuth flow #496

Closed

Description

@frahlg

Bug Description

A Discord tester reported MyUplink auth fails during startup:

MyUplink: token request failed: HTTP 400: {"error":"invalid_client","error_description":"check authorization server configuration","code":"invalid_client","description":"check authorization server configuration"}

The current Lua driver posts directly to https://api.myuplink.com/oauth/token with grant_type=client_credentials, client_id, client_secret, and scopes READSYSTEM WRITESYSTEM.

The tester reports that the MyUplink developer web portal does not expose a client_credentials app type or selectable READSYSTEM / WRITESYSTEM scopes. The iOS app also does not list a forty-two-watts client, which is expected because this should be a web developer portal app, not an iOS app.

Evidence

  • drivers/myuplink.lua fetch_token() uses grant_type=client_credentials.
  • Current dev.myuplink.com frontend bundle references Azure B2C authorization-code/PKCE flow and scopes in the form .../api/READSYSTEM .../api/WRITESYSTEM; it does not contain client_credentials.
  • No existing GitHub issue found for myuplink oauth invalid_client client_credentials.

Expected Behavior

The driver setup docs and implementation should match the auth flow available to a normal MyUplink developer portal app, or clearly state that the driver requires a special app/API capability.

Actual Behavior

A normal-looking portal client produces invalid_client at token request time, before any device polling starts.

Proposed Direction

Investigate whether MyUplink API v2 now requires authorization-code + refresh-token flow for user-owned systems. If so, replace or supplement the driver auth with a setup flow that obtains and stores a refresh token, then uses refresh-token grants at runtime.

Environment

  • Component: drivers/myuplink.lua
  • Verification status: experimental driver
  • Reporter: Discord Göran Andersson in #troubleshooting

Activity

  1. frahlg commented on Jun 20, 2026

    @frahlg
    MemberAuthor

    Additional Discord evidence: reporter shared a screenshot of the MyUplink developer portal app edit screen. It exposes Application Name, Description, Callback Url, Client Identifier, Client Secret, and Create new client secret/Save/Remove buttons. No visible grant-type selector or explicit scope selector is present on that screen. Secret was masked in the screenshot.

  2. frahlg commented on Jun 20, 2026

    @frahlg
    MemberAuthor

    Root cause confirmed + fix in #497

    Confirmed: MyUplink's developer portal only issues authorization-code apps (Callback URL + Client Identifier + Client Secret, on Azure B2C). The client_credentials grant the driver used is not offered for these apps, so it fails with invalid_client at the token request — before the callback is ever involved. This matches reference integrations (Home Assistant myuplink, MarshFlattsFarm's NIBE scripts), which all use authorization_code + offline_access → refresh_token.

    Correction on the earlier troubleshooting advice: the driver has no mode field. The mode: hotwater | heating suggestion was wrong — myuplink.lua is read-only telemetry for one physical pump (compressor power + hot-water/indoor/outdoor temps) and does not split into hot-water/heating instances. Apologies for the noise.

    Fix (#497):

    • The driver now uses grant_type=refresh_token at runtime; rotated tokens are persisted (new host.persist_secret capability) so they survive restarts.
    • A one-time in-app consent (Settings → Devices → Connect to MyUplink) handles the browser sign-in — no hand-pasting tokens. The UI shows the exact Callback URL to register in the portal.
    • Bonus: a Heat pump dashboard card now surfaces the hp_* telemetry.

    Setup guide: docs/myuplink-oauth.md. Note the HTTPS-callback caveat — if the portal rejects a plain-http LAN callback, use your HTTPS (relay) address as the callback and start the connect from there.

  3. added a commit that references this issue on Jun 20, 2026
    48f972b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions