Skip to content

Log OAuth requests and responses - #5506

Merged
hughns merged 2 commits into
developfrom
hughns/log-oauth-requests
Aug 31, 2026
Merged

Log OAuth requests and responses#5506
hughns merged 2 commits into
developfrom
hughns/log-oauth-requests

Conversation

@hughns

@hughns hughns commented Aug 28, 2026

Copy link
Copy Markdown
Member

The OAuth 2.0 flows in src/oauth/ called fetch directly, so none of the requests to the identity provider's registration, device authorization, token or revocation endpoints showed up in the logs. That makes debugging login and token refresh problems noticeably harder than debugging Client-Server API calls, which FetchHttpApi logs.

This adds a fetchWithLogging wrapper that emits the same --> / <-- debug lines as FetchHttpApi, and uses it for every OAuth 2.0 request:

OAuth2: --> POST https://auth.org/token
OAuth2: <-- POST https://auth.org/token [42ms 200]

As in FetchHttpApi, neither the request nor the response body is logged, and query parameter values are redacted — these requests routinely carry credentials. sanitizeUrlForLogs has been lifted out of FetchHttpApi into src/http-api/logging.ts so both can share it, with no change in behaviour.

OAuth2, OAuth2.registerClient, startDeviceAuthorization and waitForDeviceAuthorization now accept an optional Logger so callers can route these lines to the logger of their choice (e.g. a MatrixClient's logger). All of them default to the js-sdk root logger, so this is backwards compatible.

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • Sign-off given on the changes (see CONTRIBUTING.md).

🤖 Generated with Claude Code (with review by human)

@hughns
hughns requested a review from a team as a code owner August 28, 2026 13:04
@hughns
hughns requested review from dbkr and t3chguy August 28, 2026 13:04
The OAuth 2.0 flows in `src/oauth` called `fetch` directly, so none of the
requests to the identity provider's registration, device authorization, token
or revocation endpoints appeared in the logs. This made debugging login and
token refresh problems much harder than debugging Client-Server API calls,
which `FetchHttpApi` logs.

Add a `fetchWithLogging` wrapper which emits the same `-->`/`<--` debug lines
as `FetchHttpApi`, including the request duration and the response status, and
use it for all OAuth 2.0 requests. As with `FetchHttpApi`, neither the request
nor the response body is logged and query parameter values are redacted, since
they routinely carry credentials.

`OAuth2`, `OAuth2.registerClient`, `startDeviceAuthorization` and
`waitForDeviceAuthorization` all take an optional `Logger` so that callers can
route these lines to the logger of their choice; they default to the js-sdk
root logger.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Hugh Nimmo-Smith <hughns@matrix.org>
@hughns

hughns commented Aug 28, 2026

Copy link
Copy Markdown
Member Author

Please let me know if there is a preferred way to wire up the logger.

@hughns hughns changed the title Log OAuth 2.0 requests and responses Log OAuth requests and responses Aug 28, 2026
Comment thread src/oauth/fetch.ts
Comment thread src/http-api/logging.ts
@hughns
hughns added this pull request to the merge queue Aug 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 28, 2026
@hughns
hughns added this pull request to the merge queue Aug 31, 2026
Merged via the queue into develop with commit 300b188 Aug 31, 2026
34 checks passed
@hughns
hughns deleted the hughns/log-oauth-requests branch August 31, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants