Skip to content

fix: return error when OAuth token response is missing access_token#5

Merged
privateip merged 1 commit intoitential:mainfrom
privateip:fix/oauth-missing-token-error
Mar 9, 2026
Merged

fix: return error when OAuth token response is missing access_token#5
privateip merged 1 commit intoitential:mainfrom
privateip:fix/oauth-missing-token-error

Conversation

@privateip
Copy link
Member

Description

When the OAuth token endpoint returns HTTP 200 but the response body either fails to decode or omits the access_token field, the client was silently marking itself authenticated with an empty token. Subsequent requests were sent without a Bearer header, with no error surfaced to the caller.

Type of Change

  • Bug fix

Changes Made

  • authenticatePlatform: return a descriptive error if JSON decoding fails ("decode OAuth token response: ") or if access_token is absent or empty ("OAuth token response missing access_token field")
  • TestOAuthMissingTokenReturnsError: replaces the old test that asserted missing token was silently ignored; now asserts an error containing "access_token" is returned
  • TestOAuthInvalidJSONReturnsError: replaces the old test that asserted malformed JSON still succeeded; now asserts an error is returned

Testing

go test ./... — all 40 tests pass
CGO_ENABLED=1 go test -race ./... — no races detected

Checklist

  • Code follows the project's style guidelines
  • Self-review of code has been performed
  • Code has been commented where necessary
  • Commits follow conventional format (type: subject)
  • No secrets or credentials committed
  • Documentation has been updated accordingly

When the OAuth token endpoint returns HTTP 200 but the response body
either fails to decode or omits the access_token field, the client was
silently marking itself authenticated with an empty token. Subsequent
requests were sent without a Bearer header, with no error surfaced to
the caller.

- [x] Bug fix

- `authenticatePlatform`: return a descriptive error if JSON decoding
  fails ("decode OAuth token response: <err>") or if access_token is
  absent or empty ("OAuth token response missing access_token field")
- `TestOAuthMissingTokenReturnsError`: replaces the old test that
  asserted missing token was silently ignored; now asserts an error
  containing "access_token" is returned
- `TestOAuthInvalidJSONReturnsError`: replaces the old test that
  asserted malformed JSON still succeeded; now asserts an error is
  returned

go test ./... — all 40 tests pass
CGO_ENABLED=1 go test -race ./... — no races detected

- [x] Code follows the project's style guidelines
- [x] Self-review of code has been performed
- [x] Code has been commented where necessary
- [x] Commits follow conventional format (`type: subject`)
- [x] No secrets or credentials committed
- [x] Documentation has been updated accordingly
@privateip privateip requested a review from a team as a code owner March 8, 2026 15:49
@privateip privateip requested a review from a team March 8, 2026 15:49
@privateip privateip added the bug Something isn't working label Mar 8, 2026
@privateip privateip merged commit d70cf4d into itential:main Mar 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant