Repository navigation
MyUplink: authorization-code OAuth + in-app consent + heat-pump dashboard - #497
Merged
Merged
Conversation
…okens Drivers can now durably persist a rotated secret (e.g. an OAuth refresh_token) via host.persist_secret(key, value). The registry routes it to the unwatched state KV — never config.yaml — so a token rotation can't trigger a configreload restart loop. SecretOverride layers the KV value back over config.yaml at driver_init so the freshest token survives a restart while config.yaml keeps the bootstrap seed. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The MyUplink developer portal issues authorization-code apps, not client_credentials, so the old grant returned invalid_client before any polling started. The driver now runs grant_type=refresh_token at runtime using a refresh_token obtained via the in-app OAuth connect flow, and persists the rotated token via host.persist_secret. With no refresh_token configured it idles quietly (awaiting connect) instead of erroring. There is no `mode` field — corrects earlier misinformation; this is read-only telemetry for one physical pump. Co-Authored-By: Claude Opus 4.8 <[email protected]>
GET /api/oauth/myuplink/start mints a single-use state and returns the MyUplink authorize URL plus the exact callback URL to register in the portal. GET /api/oauth/myuplink/callback exchanges the code for a refresh_token, persists it to the driver config (masked) and the unwatched state KV (so SecretOverride supersedes any stale rotated value), restarts the driver, and renders a standalone result page. Co-Authored-By: Claude Opus 4.8 <[email protected]>
On a remote/relay origin the request Host the server sees is not the browser's origin, so a server-derived redirect_uri would be wrong. The browser now passes location.origin's callback URL; the server validates it (absolute http(s), exact callback path, no query/fragment) to prevent turning the authorize state into an open redirect, and falls back to the request origin for plain LAN access. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The apicreds device card now shows the exact Callback URL to register in the MyUplink portal, a Connect to MyUplink button, and a Connected/Not connected badge driven by whether a refresh_token is saved. Connect calls /api/oauth/myuplink/start (passing the browser's own callback URL) and opens the consent in a new tab. Also corrects the stale client_credentials copy to authorization-code. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Adds a Heat pump card to the dashboard that surfaces the MyUplink driver's hp_* metrics (compressor power + hot-water/indoor/outdoor temperatures) plus a 24h compressor-power sparkline from /api/series. The section stays hidden until a driver reports hp_power_w; discovery runs once and steady-state polling only touches heat-pump drivers. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
The auto-callback can't reach the Pi on every origin: the relay/home route refuses /api/*, and the MyUplink portal may reject a non-HTTPS LAN callback. Add POST /api/oauth/myuplink/exchange — the operator pastes the redirected URL (carrying code + state) and the Pi exchanges the code over its own outbound HTTPS, so onboarding works on relay, headless, and http LAN origins with no inbound callback. Shared consent-completion logic (completeMyUplinkConsent) backs both the GET callback and the POST exchange; consent-state TTL bumped to 15 min for the paste path. Settings → Devices gains a 'Not redirected back? Paste the URL' fallback. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Always send a code_challenge on /authorize and the code_verifier on token exchange (RFC 7636). Harmless if MyUplink ignores PKCE, required if its Azure B2C app enforces it — defensive so the consent flow doesn't fail at the authorize step. The verifier is bound to the pending state and never leaves the Pi. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A Discord tester (and soon Fredrik) hit
invalid_clientwhen setting up the MyUplink/NIBE heat-pump driver (#496). Root cause: the driver used theclient_credentialsOAuth grant, but the MyUplink developer portal only issues authorization-code apps (Callback URL + Client Identifier + Client Secret, Azure B2C).client_credentialsis simply not offered, so a normal portal app fails at the token request before any polling starts.Separately, the heat-pump telemetry the driver already emits (
hp_*) had no UI — it only showed as raw live metrics in the per-driver Diagnose modal. And the earlier troubleshooting guidance about amode: hotwater | heatingconfig was wrong: the driver has nomodefield.What
Auth (closes #496) — authorization-code + refresh-token, with in-app consent:
drivers/myuplink.luanow runsgrant_type=refresh_tokenat runtime and persists Azure-B2C-rotated tokens. With no token yet it idles quietly ("awaiting OAuth connect") instead of erroring.GET /api/oauth/myuplink/start(mints state, returns the authorize URL + the exact callback URL to register) andGET /api/oauth/myuplink/callback(exchanges the code, stores the refresh token, restarts the driver, renders a result page).host.persist_secret(key, value)capability: drivers durably store a rotated secret in the unwatched state KV (notconfig.yaml, which would trigger a config-reload restart loop).SecretOverridelayers it back over config atdriver_init, so the freshest token survives a restart whileconfig.yamlkeeps the bootstrap seed the UI shows as "saved".location.origincallback (validated server-side) so the flow works over a relay origin too.Heating UI:
/api/series). Hidden until a driver reportshp_power_w.Docs:
docs/myuplink-oauth.mdsetup walkthrough (incl. the HTTPS-callback caveat and an explicit "there is nomodefield" correction);host.persist_secretdocumented.Testing
host.persist_secret(granted + not-granted), driver refresh-token flow + rotation persistence + not-connected idle, OAuthstart/callback(state lifecycle, code exchange, config+KV persistence, redirect_uri validation/rejection).make verifygreen./api/drivers/{name}live metrics,/api/seriessparkline data,/api/oauth/myuplink/startauthorize URL + 400 on a bad redirect_uri, and the rendered Heat pump dashboard card (screenshot-verified, on-theme).🤖 Generated with Claude Code
Onboarding reachability (added)
The automatic OAuth callback can't reach the Pi on every origin: the relay/home route refuses
/api/*(owner data stays P2P), and the MyUplink portal may reject a non-HTTPS LAN callback. So consent also has a manual fallback:POST /api/oauth/myuplink/exchange— the operator pastes the redirected URL (carryingcode+state) and the Pi exchanges the code over its own outbound HTTPS. No inbound callback is needed, so onboarding works on relay, headless, and http-LAN origins. Both paths sharecompleteMyUplinkConsent; consent-state TTL is 15 min.Verified live:
/api/oauth/myuplink/exchangereaches the real token endpoint with a valid minted state (returnsinvalid_clientonly because the test creds are fake — the happy path is unit-tested against a stub).