8000 Show a Forbidden page for Account Console 401/403 API errors by edewit · Pull Request #55664 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Show a Forbidden page for Account Console 401/403 API errors - #55664

Open
edewit wants to merge 4 commits into
keycloak:mainfrom
edewit:fix/account-ui-forbidden-error
Open

edewit wants to merge 4 commits into
keycloak:mainfrom
edewit:fix/account-ui-forbidden-error

Conversation

@edewit
@edewit edewit commented Nov 30, 2026
Copy link
Copy Markdown
Contributor

Closes #40100

Account Console v3 was routing API failures through a router ErrorPage without the error object, so impersonating a user without manage-account showed a generic unexpected-error dialog. This restores clearer Forbidden UX and aligns error wiring with the Admin Console.

Decisions and assumptions

  • Kept the ErrorBoundary wiring from make account use the ErrorBoundary #40141 (ErrorBoundaryProvider + usePromise → showBoundary), and dropped that PR's content.json change (static theme resource, not Account REST).
  • Added ApiError.status and an Account ErrorRenderer that maps HTTP 401/403 to the former v2 needAccessRights copy, with Sign out as the primary action.
  • Assumes callers that use exported usePromise wrap the tree in ErrorBoundaryProvider, matching Admin Console useFetch.

AI agents were used to help implement this change.

@edewit
edewit marked this pull request as ready for review December 3, 2026 08:53
@edewit
edewit requested review from a team as code owners December 3, 2026 08:53
Copilot AI balanced review requested due to automatic review settings December 3, 2026 08:53
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The required context breaks documented KeycloakProvider-only consumers, while aborted requests can trigger global errors and empty or non-JSON 401/403 responses incorrectly show generic errors.

3 open issues
What changed in this PR

Improves Account Console permission-error handling for users without manage-account, addressing #40100.

Changes:

  • Adds HTTP status to API errors and Forbidden messaging for 401/403 responses.
  • Routes asynchronous failures through a shared error boundary.
  • Provides Sign out for permission errors and Try again for other failures.
File Description
js/​apps/​account-ui/​src/​utils/​usePromise.ts Sends promise failures to the shared boundary.
js/​apps/​account-ui/​src/​root/​ErrorRenderer.tsx Adds permission-aware error rendering and actions.
js/​apps/​account-ui/​src/​organizations/​Organizations.tsx Removes the local error-boundary provider.
js/​apps/​account-ui/​src/​main.tsx Installs the application-wide boundary and fallback.
js/​apps/​account-ui/​src/​api/​parse-response.ts Adds HTTP status to ApiError.
js/​apps/​account-ui/​maven-resources/​theme/​keycloak.v3/​account/​messages/​messages_en.properties Adds English Forbidden messaging.

Review effort: Balanced

@edewit
edewit commented Dec 3, 2026
Copy link
Copy Markdown
Contributor Author

Addressed the Copilot review:

  1. usePromise uses an optional error boundary and falls back to rethrowing during render when only KeycloakProvider is present, matching the documented quickstart setup. README notes the provider for Forbidden UX.
  2. parseResponse keeps response.status on non-JSON and unparseable error responses so 401/403 still map to Forbidden.
  3. Aborted requests are ignored via signal.aborted (and preserved AbortError) before showBoundary, matching Admin useFetch.

Copilot AI balanced review requested due to automatic review settings December 3, 2026 14:44
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Removing the local error-boundary provider causes the exported Organizations page to throw for consumers using only KeycloakProvider, even when API requests succeed.

1 open issue
3 resolved since last review

Review effort: Balanced

Comment on lines +32 to +35
<OrganizationTable
link={({ children }) => <span>{children}</span>}
loader={userOrgs}
>
@edewit
edewit commented Dec 3, 2026
Copy link
Copy Markdown
Contributor Author

Follow-up for the Organizations review note: ErrorBoundaryProvider now lives inside KeycloakProvider, matching the Admin pattern of a single shared boundary under the provider. Built-in consoles only add ErrorBoundaryFallback for their error UI, so exported pages such as Organizations no longer need a local provider when consumers use KeycloakProvider.

Copilot AI balanced review requested due to automatic review settings December 3, 2026 14:59
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The unconditional provider suppresses error propagation in integrations without ErrorBoundaryFallback, leaving users on a spinner instead of displaying the error.

2 open issues

Review effort: Balanced

<AlertProvider>
<Help>{children}</Help>
</AlertProvider>
<ErrorBoundaryProvider>
Wire usePromise through ErrorBoundary like the Admin Console so API
failures receive the error, and treat missing account audience/roles as
access denied instead of a generic unexpected error.

Closes keycloak#40100

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Keep usePromise working without ErrorBoundaryProvider, preserve HTTP
status on non-JSON 401/403 responses, and ignore aborted requests
before reporting errors.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Mount the shared error boundary inside KeycloakProvider so exported
Account pages and Admin useFetch work with KeycloakProvider alone.
Keep app-specific ErrorBoundaryFallback for Forbidden / error UI.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
@edewit
edewit force-pushed the fix/account-ui-forbidden-error branch from 15e5ced to a954020 Compare December 4, 2026 13:58
Copilot AI balanced review requested due to automatic review settings December 4, 2026 13:58
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical PF6 compatibility issues leave the Account Console with an unresolved hook import, a missing error-boundary provider, and error-renderer components that cannot compile.

5 open issues

Review effort: Balanced

<StrictMode>
<KeycloakProvider environment={environment}>
<Root />
<ErrorBoundaryFallback fallback={ErrorRenderer}>
@@ -1,3 +1,4 @@
import { useOptionalErrorBoundary } from "@keycloak/keycloak-ui-shared";
Use the PF6 Modal subcomponents and Content, and export
useOptionalErrorBoundary from ui-shared-pf6 for usePromise.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 14:11
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The PF6 KeycloakProvider still lacks an error boundary, causing authenticated Account UI loads and exported Organizations components to crash with “No provider found.”

4 open issues
1 resolved since last review

Review effort: Balanced

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.

Impersonating a user without 'manage-account' role triggers generic UI error message

2 participants

0