Log OAuth requests and responses - #5506
Merged
Merged
Conversation
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
force-pushed
the
hughns/log-oauth-requests
branch
from
August 28, 2026 13:05
6158970 to
6a8fd6a
Compare
Member
Author
|
Please let me know if there is a preferred way to wire up the logger. |
t3chguy
approved these changes
Aug 28, 2026
t3chguy
reviewed
Aug 28, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The OAuth 2.0 flows in src/oauth/ called
fetchdirectly, 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, whichFetchHttpApilogs.This adds a
fetchWithLoggingwrapper that emits the same-->/<--debug lines asFetchHttpApi, and uses it for every OAuth 2.0 request:As in
FetchHttpApi, neither the request nor the response body is logged, and query parameter values are redacted — these requests routinely carry credentials.sanitizeUrlForLogshas been lifted out ofFetchHttpApiintosrc/http-api/logging.tsso both can share it, with no change in behaviour.OAuth2,OAuth2.registerClient,startDeviceAuthorizationandwaitForDeviceAuthorizationnow accept an optionalLoggerso callers can route these lines to the logger of their choice (e.g. aMatrixClient's logger). All of them default to the js-sdk root logger, so this is backwards compatible.Checklist
public/exportedsymbols have accurate TSDoc documentation.🤖 Generated with Claude Code (with review by human)