Skip to content

fix: restore entra auth setup flow#99

Merged
s205109 merged 4 commits intomainfrom
fix/entra-auth-setup
Apr 28, 2026
Merged

fix: restore entra auth setup flow#99
s205109 merged 4 commits intomainfrom
fix/entra-auth-setup

Conversation

@s205109
Copy link
Copy Markdown
Owner

@s205109 s205109 commented Apr 28, 2026

Summary

Brief description of changes.

Checklist

  • Tests pass (dotnet test)
  • Build succeeds (dotnet build)
  • No new warnings introduced
  • Breaking changes documented (if any)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

Test Results

2 tests   2 ✅  7s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 94e3136.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

Summary

Summary
Generated on: 04/28/2026 - 20:35:55
Coverage date: 04/28/2026 - 20:34:11 - 04/28/2026 - 20:35:51
Parser: MultiReport (10x Cobertura)
Assemblies: 6
Classes: 67
Files: 57
Line coverage: 75.7% (508 of 671)
Covered lines: 508
Uncovered lines: 163
Coverable lines: 671
Total lines: 2305
Branch coverage: 52.2% (81 of 155)
Covered branches: 81
Total branches: 155
Method coverage: Feature is only available for sponsors
Tag: 128_25075971588

Coverage

AHKFlowApp.API - 63.3%
Name Line Branch
AHKFlowApp.API 63.3% 52.9%
AHKFlowApp.API.Auth.HttpContextCurrentUser 100% 46.1%
AHKFlowApp.API.Auth.TestAuthenticationHandler 100%
AHKFlowApp.API.Controllers.DevController 100%
AHKFlowApp.API.Controllers.HealthController 100%
AHKFlowApp.API.Controllers.HotstringsController 100%
AHKFlowApp.API.Controllers.VersionController 100%
AHKFlowApp.API.Controllers.WhoAmIController 100%
AHKFlowApp.API.DevDockerSqlServer 0% 0%
AHKFlowApp.API.Extensions.ApiExtensions 100% 100%
AHKFlowApp.API.Extensions.ProblemDetailsResultExtensions 100% 100%
AHKFlowApp.API.Middleware.GlobalExceptionMiddleware 100%
AHKFlowApp.API.Models.HealthResponse 100%
AHKFlowApp.API.OpenApi.Examples.CreateHotstringDtoExample 0%
AHKFlowApp.API.OpenApi.Examples.HotstringDtoExample 0%
AHKFlowApp.API.OpenApi.Examples.PagedHotstringsExample 0%
AHKFlowApp.API.OpenApi.Examples.UpdateHotstringDtoExample 0%
AHKFlowApp.Application - 98.1%
Name Line Branch
AHKFlowApp.Application 98.1% 47%
AHKFlowApp.Application.Behaviors.ValidationBehavior`2 100%
AHKFlowApp.Application.Commands.Dev.SeedHotstringsCommandHandler 100%
AHKFlowApp.Application.Commands.Hotstrings.CreateHotstringCommandHandler 66.6% 0%
AHKFlowApp.Application.Commands.Hotstrings.CreateHotstringCommandValidator 100%
AHKFlowApp.Application.Commands.Hotstrings.DeleteHotstringCommandHandler 100%
AHKFlowApp.Application.Commands.Hotstrings.UpdateHotstringCommandHandler 100% 58.3%
AHKFlowApp.Application.Commands.Hotstrings.UpdateHotstringCommandValidator 100%
AHKFlowApp.Application.DependencyInjection 100%
AHKFlowApp.Application.DTOs.CreateHotstringDto 100%
AHKFlowApp.Application.DTOs.HotstringDto 100%
AHKFlowApp.Application.DTOs.PagedList`1 100% 50%
AHKFlowApp.Application.DTOs.UpdateHotstringDto 100%
AHKFlowApp.Application.Mapping.HotstringMappings 100%
AHKFlowApp.Application.Queries.Hotstrings.GetHotstringQueryHandler 100%
AHKFlowApp.Application.Queries.Hotstrings.ListHotstringsQuery 100%
AHKFlowApp.Application.Queries.Hotstrings.ListHotstringsQueryHandler 100%
AHKFlowApp.Application.Queries.Hotstrings.ListHotstringsQueryValidator 100%
AHKFlowApp.Application.Validation.HotstringRules 100% 100%
AHKFlowApp.Domain - 100%
Name Line Branch
AHKFlowApp.Domain 100% ****
AHKFlowApp.Domain.Entities.Hotstring 100%
AHKFlowApp.Infrastructure - 100%
Name Line Branch
AHKFlowApp.Infrastructure 100% 50%
AHKFlowApp.Infrastructure.DependencyInjection 100%
AHKFlowApp.Infrastructure.Persistence.AppDbContext 100%
AHKFlowApp.Infrastructure.Persistence.Configurations.HotstringConfiguration 100%
AHKFlowApp.Infrastructure.Persistence.Configurations.TestMessageConfigurati
on
100%
AHKFlowApp.Infrastructure.Services.VersionService 100% 50%
AHKFlowApp.TestUtilities - 57.5%
Name Line Branch
AHKFlowApp.TestUtilities 57.5% 100%
AHKFlowApp.TestUtilities.Auth.TestAuthHandler 100% 100%
AHKFlowApp.TestUtilities.Auth.TestUserBuilder 77.7%
AHKFlowApp.TestUtilities.Builders.HealthResponseBuilder 0%
AHKFlowApp.TestUtilities.Builders.HotstringBuilder 0%
AHKFlowApp.TestUtilities.Fixtures.CustomWebApplicationFactory 100% 100%
AHKFlowApp.TestUtilities.Fixtures.SqlContainerFixture 100%
AutoGeneratedProgram 0%
AHKFlowApp.UI.Blazor - 79.8%
Name Line Branch
AHKFlowApp.UI.Blazor 79.8% 48.2%
AHKFlowApp.UI.Blazor.Auth.ApiAuthorizationMessageHandler 0%
AHKFlowApp.UI.Blazor.Auth.AuthConfigurationValidator 100% 100%
AHKFlowApp.UI.Blazor.Auth.TestAuthenticationProvider 0%
AHKFlowApp.UI.Blazor.DTOs.ApiProblemDetails 100%
AHKFlowApp.UI.Blazor.DTOs.CreateHotstringDto 100%
AHKFlowApp.UI.Blazor.DTOs.HealthResponse 100%
AHKFlowApp.UI.Blazor.DTOs.HotstringDto 100%
AHKFlowApp.UI.Blazor.DTOs.PagedList`1 100%
AHKFlowApp.UI.Blazor.DTOs.UpdateHotstringDto 100%
AHKFlowApp.UI.Blazor.Layout.MainLayout 0%
AHKFlowApp.UI.Blazor.Pages.Health 100% 100%
AHKFlowApp.UI.Blazor.Pages.Hotstrings 90.9%
AHKFlowApp.UI.Blazor.Services.AhkFlowAppApiHttpClient 100%
AHKFlowApp.UI.Blazor.Services.ApiErrorMessageFactory 58.3% 26.6%
AHKFlowApp.UI.Blazor.Services.ApiResult 50%
AHKFlowApp.UI.Blazor.Services.ApiResult`1 100%
AHKFlowApp.UI.Blazor.Services.HotstringsApiClient 60% 41.6%
AHKFlowApp.UI.Blazor.Shared.LoginDisplay 100%
AHKFlowApp.UI.Blazor.Shared.RedirectToLogin 0%
AHKFlowApp.UI.Blazor.Validation.HotstringEditModel 100%

Per-assembly thresholds: Domain line≥85% br≥70% · Application line≥85% br≥45% · Infrastructure line≥70% br≥50% · API line≥57% br≥50% · UI.Blazor line≥65% br≥28%

Copy link
Copy Markdown
Owner Author

@s205109 s205109 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build & tests: Builds cleanly (

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Restores and hardens the local Entra ID authentication setup flow for the Blazor frontend by improving configuration validation, enhancing the sign-in failure UX, and making the Entra setup script more robust/consistent.

Changes:

  • Added a centralized AuthConfigurationValidator (used at startup) plus unit tests for missing/placeholder config scenarios.
  • Improved the auth failure UI (Authentication.razor) with dev-only guidance for common local Entra setup issues.
  • Updated setup-entra-app.ps1 to create/verify the service principal and wait for Entra/Graph changes to become visible; documentation updated accordingly.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/AHKFlowApp.UI.Blazor.Tests/Shared/LoginDisplayTests.cs Adds bUnit tests verifying LoginDisplay navigates to login/logout routes based on auth state.
tests/AHKFlowApp.UI.Blazor.Tests/Auth/AuthConfigurationValidatorTests.cs Adds unit tests for MSAL configuration validation behavior.
src/Frontend/AHKFlowApp.UI.Blazor/Shared/LoginDisplay.razor Minor formatting; keeps login/logout navigation behavior.
src/Frontend/AHKFlowApp.UI.Blazor/Program.cs Replaces inline required-key checks with AuthConfigurationValidator.ValidateForMsal.
src/Frontend/AHKFlowApp.UI.Blazor/Pages/Authentication.razor Adds a custom LogInFailed UI with dev-only setup guidance and a “Back to home” action.
src/Frontend/AHKFlowApp.UI.Blazor/Auth/AuthConfigurationValidator.cs New validator for required MSAL configuration + placeholder detection.
src/Frontend/AHKFlowApp.UI.Blazor/AHKFlowApp.UI.Blazor.csproj Exposes internals to the test assembly via InternalsVisibleTo.
scripts/setup-entra-app.ps1 Adds service principal creation + retry/wait logic for eventual consistency.
docs/deployment/entra-setup.md Updates setup documentation to reflect additional wiring/wait behavior and AADSTS500011 guidance.
docs/architecture/authentication.md Adds clarification about Microsoft-hosted error pages vs SPA-rendered errors.
README.md Adds first-time Entra setup guidance and AADSTS500011 troubleshooting note.
Directory.Packages.props Formatting-only change.

Comment thread scripts/setup-entra-app.ps1 Outdated
Comment thread scripts/setup-entra-app.ps1 Outdated
Comment thread scripts/setup-entra-app.ps1 Outdated
Comment thread scripts/setup-entra-app.ps1 Outdated
Comment thread src/Frontend/AHKFlowApp.UI.Blazor/Auth/AuthConfigurationValidator.cs Outdated
- ConvertFrom-JsonSafe wrapper avoids ConvertFrom-Json throw on empty/non-JSON
  az output (failed sp lookups, transient Graph reads in retry loops).
- AuthConfigurationValidator also rejects placeholder in AzureAd:DefaultScope.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@s205109
Copy link
Copy Markdown
Owner Author

s205109 commented Apr 28, 2026

Reviewed the 5 Copilot comments — all valid, all addressed in cbbf352:

  • ConvertFrom-Json on potentially-empty az stdout → introduced ConvertFrom-JsonSafe helper (returns $null on empty/non-JSON), replaced all four call sites + the matching pre-loop currentScopes lookup that had the same bug.
  • AuthConfigurationValidator now also rejects < in AzureAd:DefaultScope; added a dedicated test case.

Additional issues found while reviewing

  1. Config key drift in Program.cs — the test-auth branch reads the API base URL from "ApiBaseUrl" (line 56), the MSAL branch from "ApiHttpClient:BaseAddress" (line 71). Two keys for the same value invites future drift; pick one. Not blocking this PR but worth a follow-up.

  2. LoginDisplayTests.BuildConfiguration(useTestAuth) — both call sites pass false. The parameter is dead code; either drop it or add a useTestAuth: true test for the inverse path.

  3. Wait-ForCondition 60 s ceiling (12 × 5s) — Graph/Entra propagation is occasionally slower than that on cold tenants. Consider parameterising or bumping to e.g. 90 s for the SP visibility wait, which is the most propagation-bound of the four.

None are blockers — happy to land them in a follow-up if you'd rather keep this PR scoped to the auth-restore fix.

- Unify config key: test-auth path now reads ApiHttpClient:BaseAddress
  (was ApiBaseUrl); update appsettings.Local.json + appsettings.E2E.json.
- Add test for disabled logout in test-auth mode; use IAsyncLifetime to
  avoid sync-dispose throw on MudBlazor PopoverService.
- Bump SP propagation wait to 90s (18x5s) in setup-entra-app.ps1.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@s205109
Copy link
Copy Markdown
Owner Author

s205109 commented Apr 28, 2026

@copilot can you fix the test errors in the last run?

…iBaseUrl

Commit 8da70b7 changed Program.cs (test-auth branch) to read
ApiHttpClient:BaseAddress instead of ApiBaseUrl, but SpaHost.cs still
injected ApiBaseUrl into the intercepted appsettings responses.
The base appsettings.json has ApiHttpClient:BaseAddress=http://localhost:5600,
so E2E tests sent all API calls to localhost:5600 (unreachable in CI)
rather than the local test proxy, causing td.draft-row timeouts.

Agent-Logs-Url: https://github.com/s205109/AHKFlowApp/sessions/2ed7e782-fe49-415e-974a-0b3bcc50d9ba

Co-authored-by: s205109 <4550557+s205109@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

@copilot can you fix the test errors in the last run?

Fixed in 94e3136. The root cause was a config key mismatch introduced in the previous commit (8da70b7): Program.cs was updated to read ApiHttpClient:BaseAddress (instead of ApiBaseUrl) in the test-auth branch, but SpaHost.cs still injected ApiBaseUrl: "/". Since the base appsettings.json already has ApiHttpClient:BaseAddress = "http://localhost:5600", the Blazor app computed the API base as http://localhost:5600 (unreachable in CI), so all hotstring API calls timed out — the page never rendered rows and td.draft-row was never visible. One-line fix: SpaHost.cs now injects ApiHttpClient: { BaseAddress: "/" } instead of ApiBaseUrl: "/" to match.

@s205109 s205109 merged commit 23764e8 into main Apr 28, 2026
3 checks passed
@s205109 s205109 deleted the fix/entra-auth-setup branch April 28, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants