Classify token-endpoint refusals by OAuth error code, not by 401
bc3 is moving a body-authenticated invalid_client from a bare 401 to a 400 (RFC 6749 §5.2, RFC 9110 §15.5.2). A Basic-auth invalid_client stays 401 with a Basic challenge. TypeScript, Ruby and Python treated a token error as auth_required only when it was a 401 or invalid_grant. After the bc3 change, a refused client would show up as api_error.
The rule, in every SDK with OAuth
| Response | Code |
|---|---|
error is invalid_grant, invalid_client, unauthorized_client or access_denied, on any status | auth_required |
| 401, whatever the body (OAuth error object, other JSON, HTML, empty) | auth_required |
| anything else | api_error (with the status) |
This is pinned in conformance/oauth-token: fixtures 08–17 are new, and 04/05 now name their code. Go, TypeScript, Python, Ruby and Rust run those fixtures directly; Kotlin mirrors them in OAuthTest.kt. The schema now requires code on every reject fixture, so a harness can't pass just because the call failed. It also accepts rawBody for non-JSON responses. The rule is written up in SPEC §16, "Token Endpoint Error Classification".
The SDKs didn't agree before this
The brief assumed Go and Kotlin already classified by error code. They didn't:
- Go
oauth.Exchanger: every non-200 came back as an untypedfmt.Errorf, so callers couldn't classify it at all. It now returns a typed*basecamp.Error. When the body had noerrormember, the old message also echoed the raw body. Now it is justtoken request failed with status N, as SPEC §9 requires: onlyerror/error_descriptionmay be rendered. - Go
AuthManagerrefresh: every non-200 wasapi_error, a 401 included. That error reaches callers throughAccessToken's proactive refresh. It now uses the same rule and renders only the parsed OAuth fields (the old message echoed the whole body). An unreadable body is now refused before classification. The rule comes from the internal packagego/pkg/basecamp/internal/oautherror(basecampandbasecamp/oauthcan't import each other). - Kotlin: every non-2xx was
Auth, including 5xx and 304.Authnow carries the real status through a newinternalconstructor; the public constructor's signature is unchanged. - Rust: already classified by code, with the four codes above plus any 401. It mapped other 400/422 responses to
validation; those are nowapi_error. It still maps 429 torate_limit(retryable) and treats a 5xx as a retryableapi_error. No fixture pins either of those, and the SPEC section records both. - TypeScript / Ruby / Python: the set was only
invalid_grant, and a 401 with a non-JSON body became a parse-failureapi_errorbefore the classifier ran. Fixtures 12 and 13 showed that.
Decisions
access_deniedis in the set (the brief listed three codes). Rust already included it, SPEC §16 maps the device flow'saccess_deniedtoauth_required, and signing in again is the right response wherever the token endpoint returns it.- Any 401 is
auth_required, even with a parseable code outside the set (fixture 14). The brief only required this for a 401 without a parseable OAuth body. Narrowing it would have moved, for example, a 401invalid_requestfromauth_requiredtoapi_errorin every SDK, with nothing gained. - The device flow is unchanged. Every SDK's poll classifies by error code (
authorization_pending,slow_down,access_denied,expired_token, the 429 pair) and doesn't check for 401, so movinginvalid_clientfrom 401 to 400 doesn't change its outcome. Unknown codes stay a terminalapi_error, as SPEC §16 specifies. - Revoke: no SDK has an OAuth revoke call.
- Not touched: the Ruby
OauthTokenProviderand PythonOAuthTokenProvider/async variant are legacy and Launchpad-only. They raise their auth error for any refused refresh, soinvalid_clienton a 400 is already auth there.
Failing first
On the old code the new fixtures failed 5 each in TypeScript, Ruby and Python (08, 09, 11, 12, 13) and all 10 in Go. Rust failed on 15, Kotlin on its mirror test plus the 304 test, and Go AuthManager on 7 of 10 table cases. Everything passes on this branch.
Summary by cubic
Classifies token-endpoint refusals by OAuth error code, not by 401, across all SDKs, so a body-authenticated invalid_client answered with a 400 (RFC 6749 §5.2) surfaces as auth_required rather than api_error.
The rule
invalid_grant,invalid_client,unauthorized_client, oraccess_denied, on any status, isauth_required.- Any 401 is
auth_required, whatever its body. - Everything else is
api_errorcarrying the status.
Per-SDK changes
- TypeScript: a body-less or non-JSON refusal is classified by status alone, never sent through the body reader (which failed closed on a null body without a Content-Length) or turned into a parse-failure
api_error. - Go:
oauth.Exchangerreturns typed*basecamp.Error;AuthManagerrefresh classifies via the sharedinternal/oautherrorpackage. Both render only the RFC 6749error/error_descriptionor the status, never the raw refusal body, which can echo what was sent (SPEC §9). - Kotlin: no longer raises
Authfor every non-2xx (5xx and 304 are nowapi_error), andAuthnow carries the refusal's actual HTTP status instead of a hard-coded 401. - Rust: other 400/422 responses drop the
validationmapping; 429 staysrate_limitand 5xx a retryableapi_error. - Ruby and Python: non-JSON 401 bodies no longer become a parse-failure
api_error.
New conformance fixtures 08–17 and a schema requirement that rejections name their code pin the rule across SDKs.