Skip to content

Refactor OidcEndpoints to use MediatR commands/handler pattern#1256

Merged
StuartFerguson merged 11 commits intomasterfrom
copilot/refactor-oidc-endpoints
Apr 12, 2026
Merged

Refactor OidcEndpoints to use MediatR commands/handler pattern#1256
StuartFerguson merged 11 commits intomasterfrom
copilot/refactor-oidc-endpoints

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

  • Create SecurityService/Factories/OidcResponseFactory.cs with FromResult overloads for each OIDC result type
  • Update each OIDC handler to call OidcResponseFactory.FromResult(result) and drop its private ToIResult method

Copilot AI linked an issue Apr 10, 2026 that may be closed by this pull request
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 10, 2026

Not up to standards ⛔

🔴 Issues 1 medium · 1 minor

Alerts:
⚠ 1 issue (≤ 0 issues of at least medium severity)

Results:
2 new issues

Category Results
BestPractice 1 medium
CodeStyle 1 minor

View in Codacy

🟢 Metrics 25 complexity · 0 duplication

Metric Results
Complexity 25
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copilot AI and others added 2 commits April 10, 2026 21:05
- 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>
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
Copilot AI requested a review from StuartFerguson April 10, 2026 21:10
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>
@StuartFerguson StuartFerguson marked this pull request as ready for review April 11, 2026 09:11
…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>
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.
@StuartFerguson StuartFerguson merged commit cc27646 into master Apr 12, 2026
8 of 9 checks passed
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.

OidcEnpoints refactor

2 participants