# demarkus-library — Debugging & Gotchas Bugs, gotchas, and investigations. Highest-recall file — check here first when something behaves strangely. ## OAuth Basic auth vs the broker: form-urlencode BEFORE Basic-encoding RFC 6749 §2.3.1: token-endpoint Basic credentials are `client_id` and `client_secret` **form-urlencoded first**, then joined and base64'd. The broker enforces this (`client_auth.go` QueryUnescapes both halves after decoding). A naive `req.SetBasicAuth(clientID, secret)` works only while the secret has no reserved characters — a secret containing `:` or `%` silently desyncs and the broker sees a different secret → `401 invalid_client` that looks like a wrong secret in config. The library client escapes both halves (`oauth.Client.setBasicAuth`), and the test secret deliberately contains `:` and `%` to pin it. ## Broker refresh does not rotate refresh tokens Refresh responses omit `refresh_token` (omitempty). If client code treats an empty `refresh_token` in the response as "clear the stored one", every session dies on first refresh. `session.Manager` only overwrites when non-empty. ## Broker invalid_grant on token exchange does not consume the code on client errors Wrong client_id / redirect_uri / verifier keep the code redeemable for the 60-second window (broker's keep-code-on-client-error semantics) — retrying a misconfigured exchange can still succeed after a config fix within the window. But a *consumed* or expired code is permanently `invalid_grant` → fresh login.