fix(matrix): add debug logging for OIDC registration and deduplicate redirect normalization#957
fix(matrix): add debug logging for OIDC registration and deduplicate redirect normalization#957
Conversation
…redirect normalization Users behind a reverse proxy report that Matrix OIDC still fails with `invalid_redirect_uri` after the ApplicationType::Web fix (#893). The only log line visible is the final WARN from the dispatch layer, making it impossible to diagnose why MAS rejects the redirect URI. Add debug-level logging throughout the OIDC registration flow: - Server metadata (issuer, registration endpoint) - Client registration parameters (redirect_uri, application type) - Full serialized client metadata sent to MAS - Enhanced error WARN with both Display and Debug error formats - Gateway-level log of the redirect_uri received from the frontend Also fix duplicated loopback normalization: build_client_metadata() had its own copy of the https→http rewrite that duplicated normalize_loopback_redirect(). Now it receives the pre-normalized URI, eliminating the maintenance hazard. Pass the normalized URI consistently to both build_client_metadata() and client.oauth().login(). Discussion: #872
Greptile SummaryThis PR adds structured debug logging to the Matrix OIDC registration flow and deduplicates the loopback redirect URI normalization, moving it entirely into
Confidence Score: 5/5Safe to merge — changes are additive logging only with a low-risk normalization refactor backed by passing tests. All functional logic is unchanged: the loopback normalization deduplication produces identical runtime behavior since No files require special attention.
|
| Filename | Overview |
|---|---|
| crates/matrix/src/oidc.rs | Added ClientRegistrationDiagnostics and ClientRegistrationFailure helper types; deduped loopback normalization so callers pre-normalize before passing to build_client_metadata; added structured debug/warn logging throughout start_oidc_login; tests updated and two new tests added. |
| crates/gateway/src/channel.rs | Added a single debug! log at the entry of oauth_start recording account_id and the raw redirect_uri string received from the frontend. |
Sequence Diagram
sequenceDiagram
participant FE as Frontend
participant GW as channel.rs (oauth_start)
participant OI as oidc.rs (start_oidc_login)
participant MAS as MAS Server
FE->>GW: oauth_start(account_id, redirect_uri)
GW->>GW: debug log: channels.oauth_start called
GW->>OI: start_oidc_login(client, account_id, redirect_uri)
OI->>MAS: server_metadata()
MAS-->>OI: issuer, registration_endpoint
OI->>OI: debug log: server metadata discovered
OI->>OI: normalize_loopback_redirect(redirect_uri) → registration_redirect
OI->>OI: build_client_metadata(registration_redirect)
OI->>OI: debug log: client registration parameters
OI->>OI: Raw::new(&metadata) → raw_metadata
OI->>OI: ClientRegistrationDiagnostics::new(...)
OI->>OI: debug log: full client metadata JSON
OI->>MAS: oauth().login(registration_redirect, ..., registration_data).build()
alt Success
MAS-->>OI: OAuthAuthorizationData { url, state }
OI->>OI: info log: OIDC login started
OI-->>GW: OidcLoginPending
GW-->>FE: result
else Failure
MAS-->>OI: Error
OI->>OI: ClientRegistrationFailure::new(diagnostics, error)
OI->>OI: warn log: registration failed + full diagnostics
OI-->>GW: ChannelError
GW-->>FE: error
end
Reviews (3): Last reviewed commit: "fix(matrix): surface OIDC registration d..." | Re-trigger Greptile
Merging this PR will degrade performance by 21.65%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | env_substitution |
10.9 µs | 14 µs | -21.65% |
Comparing festive-plume (455dac1) with main (347376c)
Footnotes
-
5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Summary
invalid_redirect_urifailures (discussion matrix OIDC on a reverse proxy does not work #872)build_client_metadata()no longer has its own copy of the https→http rewritebuild_client_metadata()andclient.oauth().login()With
RUST_LOG=moltis_matrix=debug,moltis_gateway=debug, the following is now logged:channels.oauth_start called)ClientMetadataJSON sent to the MAS registration endpointDisplayandDebugerror formats (the Debug format often includes the HTTP response body from MAS)Validation
Completed
cargo test -p moltis-matrix -- oidc::tests— all 12 tests passcargo fmt --all -- --check— cleancargo clippy -p moltis-matrix -p moltis-gateway -- -D warnings— cleanRemaining
./scripts/local-validate.shManual QA
RUST_LOG=moltis_matrix=debug,moltis_gateway=debug