Carry a token refusal's OAuth error and Retry-After, and type device authorization's 429
Stacked on #971, which made the Go token-endpoint refusals typed; this builds on that typed error, and GitHub will retarget it to main when #971 merges.
What
A token-endpoint or device-authorization refusal now carries what the server said, on *basecamp.Error:
OAuthErrorandOAuthErrorDescription: the RFC 6749erroranderror_description. Both are bounded the way the message is, and nothing else from the body is rendered (SPEC §9).RetryAfter: the wait fromRetry-After, parsed by the client's own §6 parser.ParseRetryAfterexports that parser so theoauthpackage reads the header the same way.- A 429 is
rate_limitin the Exchanger and inAuthManagerrefresh. Rules 1 and 2 still come first, soinvalid_granton any status is stillauth_required. This is the same refinement Rust already makes.
RequestDeviceAuthorization gets the same treatment. A 4xx body's error and error_description go into the typed fields and the message. A 429 is rate_limit with its RetryAfter, and everything else stays api_error with its status. Nothing becomes auth_required there, because the refusal is of the login being started, and "sign in again" doesn't fix it.
Why
A Basecamp CLI user locked themselves out. Two containers held copies of one login. The second refresh revoked it, and a scheduled job then resent the revoked token every two minutes. bc3's abuse tracker escalated to a 4-hour block on every OAuth endpoint for that client and address, device authorization included. Through the SDK:
- the refresh 429 came back as
api_errorwith no wait, so the caller's only option was to try again into the block; - the device login said
device authorization failed with status 429, with no reason and no time.
The CLI also detected invalid_grant by matching "token error: invalid_grant" in the message. With OAuthError it can match the code.
Decisions
- Go only. The CLI is the consumer that needs this. SPEC §16 records the Go behavior the same way it already records Rust's 429 refinement and other "Go only, today" rules. The other SDKs keep their current classification.
- Device authorization reads a 4xx body; it used to read none. The old code classified every non-2xx before reading, so a stalled body couldn't turn into a retryable transport failure. That guarantee still holds: a body that can't be read, or is over the cap, leaves the status to classify alone, and cancellation still wins. A 3xx or 5xx is still classified without a read. The cost is that a stalled 4xx body now takes up to the request timeout before it fails as an
api_error, instead of failing at once. - New fields on
basecamp.Error, not a new error type. Callers already classify witherrors.As(*basecamp.Error). Extra fields keep that working and reach theAuthManagerpath, which can't importoauth.
Testing
- New tests failed first on behavior, not just compilation: the field was added before the logic.
TestExchanger_Refresh_CarriesOAuthErrorAndRetryAfterandTestAuthManager_Refresh_CarriesOAuthErrorAndRetryAftergotapi_error/429withRetryAfter = 0and an emptyOAuthError.TestRequestDeviceAuthorization_CarriesOAuthErrorAndRetryAftergot the barestatus 429message. All pass now, along with the existing suites. TestExchanger_Refresh_BoundsOAuthErrorFields: a 10 KBerrororerror_descriptionis truncated in the typed fields as well.-
make checkpasses (macOS)
Summary by cubic
A refused token refresh or device authorization in the Go SDK now carries the server's RFC 6749 error code, description, and Retry-After wait on *basecamp.Error, so callers act on the server's own verdict instead of a bare status.
- A 429 is now
rate_limitin the Exchanger andAuthManagerrefresh, matching Rust's classification. - Device authorization reads a 4xx body's
erroranderror_descriptioninto the typed fields and message; a 429 israte_limitwith its wait, everything else staysapi_error. ParseRetryAfterexports the client's Retry-After parser so theoauthpackage reads the header the same way.OAuthErrorandOAuthErrorDescriptionare bounded like the message; the composed message is bounded too.- An unreadable or oversized refusal keeps its status-based class and Retry-After, but a caller's own cancellation during a body read surfaces as cancellation, not a refusal.