Refactor OidcEndpoints to use MediatR commands/handler pattern#1256
Merged
StuartFerguson merged 11 commits intomasterfrom Apr 12, 2026
Merged
Refactor OidcEndpoints to use MediatR commands/handler pattern#1256StuartFerguson merged 11 commits intomasterfrom
StuartFerguson merged 11 commits intomasterfrom
Conversation
Closed
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| BestPractice | 1 medium |
| CodeStyle | 1 minor |
🟢 Metrics 25 complexity · 0 duplication
Metric Results Complexity 25 Duplication 0
TIP This summary will be updated as you push new changes. Give us feedback
- Add OidcCommands.cs with four command records (Authorize, Token, Logout, UserInfo) - Add OidcRequestHandler.cs implementing IRequestHandler for each command, with all dependencies injected via constructor instead of per-endpoint parameters - Move ResolveClientCredentialsScopesAsync helper from OidcEndpoints to OidcHelpers - Replace OidcEndpoints body with thin wrappers that delegate to IMediator.Send() - Register OidcRequestHandler assembly in Program.cs MediatR configuration - Update OidcEndpointTests to test OidcRequestHandler directly and use the moved helper Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/7a8f99ca-20b5-4a64-8879-c7d4d0abc398 Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/7a8f99ca-20b5-4a64-8879-c7d4d0abc398 Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor OidcEndpoints to use commands/queries and Mediatr
Refactor OidcEndpoints to use MediatR commands/handler pattern
Apr 10, 2026
Extract private helpers to reduce cyclomatic complexity: - Handle(AuthorizeCommand): delegates auth-fail, consent-decision, and consent-type branches to HandleAuthenticationFailed, HandleConsentDecisionAsync, HandleConsentTypeAsync - Handle(TokenCommand): dispatches to HandleCodeOrRefreshTokenAsync, HandleClientCredentialsAsync, HandlePasswordGrantAsync - Handle(UserInfoCommand): delegates response building to BuildUserInfoResponseAsync - Consolidate repeated ForbidServer pattern into shared private method Each public Handle method is now under 30 lines with complexity ≤ 4 Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/0ba17972-8cbb-4946-9aef-99775a7a6b0c Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Rename all Async-suffixed methods added in the previous refactor: - OidcRequestHandler.cs: HandleConsentDecision, HandleConsentType, HandleCodeOrRefreshToken, HandleClientCredentials, HandlePasswordGrant, BuildUserInfoResponse, CompleteAuthorization - OidcHelpers.cs: CreatePrincipal, BuildScopeDisplay (both overloads), ResolveClientCredentialsScopes - Update all call sites: OidcRequestHandler.cs, Verify.cshtml.cs, Consent/Index.cshtml.cs, OidcEndpointTests.cs Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/7eef1f9f-2923-4f7f-8e9a-beae9b063339 Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
…est build error Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/ad87a1db-0141-445b-8444-0e27c7f269cb Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
…<OidcActionResult> return types Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/03e146be-feb7-4170-b6e8-204aaef5ec6c Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/466bce18-813c-430d-8157-8c1fc9758113 Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
…oint pattern Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/b709f45d-14b2-4359-8f29-2040ee3bbc26 Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
…esult Agent-Logs-Url: https://github.com/TransactionProcessing/SecurityService/sessions/8c85d7d2-b64d-4ca5-a79d-a42fea092a5e Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Generalize OidcResponseFactory.FromResult to accept Result<T> and handle all OIDC command results in a single method, reducing duplication. Introduce TranslateResultStatus for standardized error responses. Update tests and endpoint mappings to align with the new API. Add necessary using directives.
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.
SecurityService/Factories/OidcResponseFactory.cswithFromResultoverloads for each OIDC result typeOidcResponseFactory.FromResult(result)and drop its privateToIResultmethod