Skip to content

Improve first-run Aspire Keycloak auth and graceful error handling (#267) - #268

Open
fboucher wants to merge 1 commit into
v-nextfrom
kepler/267-feature/aspire-auth-first-run
Open

fboucher wants to merge 1 commit into
v-nextfrom
kepler/267-feature/aspire-auth-first-run

Conversation

@fboucher

@fboucher fboucher commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #267

  • Zero-config local dev Keycloak provisioning (Development only):
    • Added src/NoteBookmark.AppHost/Realms/notebookmark-realm.json with the notebookmark realm, confidential notebookmark OIDC client (dev-notebookmark-secret), local redirect URIs / post-logout redirect URIs / web origins, and seeded dev user (dev / dev, dev@notebookmark.local).
    • Updated src/NoteBookmark.AppHost/AppHost.cs in Development to import the dev realm via .WithRealmImport(...), wait for Keycloak OIDC discovery readiness via .WithHttpHealthCheck("/realms/notebookmark/.well-known/openid-configuration", endpointName: "http"), and forward Keycloak__Authority, Keycloak__ClientId, and Keycloak__ClientSecret to blazor-app while respecting explicit user-secret/env overrides (ignoring "KEY_HERE" placeholders).
    • Non-Development environments do not import the dev realm or inject dev-only secrets.
  • Graceful startup & login/logout error handling:
    • Added KeycloakConfigurationValidator in NoteBookmark.BlazorApp to validate Keycloak:Authority, Keycloak:ClientId, and Keycloak:ClientSecret (treating null/whitespace/KEY_HERE as unconfigured) and log a clear startup warning when incomplete.
    • Added AuthenticationEndpointHandlers and /authentication/error (AuthenticationError.razor) so unconfigured auth, OIDC discovery/connectivity errors (IDX20803 / HttpRequestException), and remote failures show a friendly, actionable error page with retry/home actions and a reference to docs/keycloak-setup.md instead of an unhandled exception.
  • Tests & Documentation:
    • Added unit tests in NoteBookmark.BlazorApp.Tests for Keycloak config validation, login/logout error handling, return URL sanitization, and AuthenticationError rendering.
    • Updated README.md and docs/keycloak-setup.md with local Aspire dev login credentials and override instructions.

Verification

  • dotnet build src/NoteBookmark.AppHost/NoteBookmark.AppHost.csproj — 0 errors, 0 nullable warnings
  • dotnet test NoteBookmark.NoMaui.slnf — all tests pass (AIServices: 31, Api: 411, BlazorApp: 208)

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Health
NoteBookmark.AIServices 97% 64% ✔
NoteBookmark.Api 90% 84% ✔
NoteBookmark.BlazorApp 37% 49% ❌
NoteBookmark.Domain 94% 75% ✔
NoteBookmark.ServiceDefaults 96% 75% ✔
NoteBookmark.SharedUI 62% 62% ➖
Summary 77% (3451 / 4506) 73% (1586 / 2183) ➖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

1 participant