From eb5afeeabbc6e74c4997f172e9a6b30fb426aa25 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 9 Oct 2024 16:20:53 +0200 Subject: [PATCH] added description to denied consent and show on ErrorPage fixes: #28328 Signed-off-by: Erik Jan de Wit --- js/apps/account-ui/src/index.ts | 1 - js/apps/account-ui/src/root/ErrorPage.tsx | 65 ------------------- js/apps/account-ui/src/routes.tsx | 3 +- js/libs/ui-shared/src/context/ErrorPage.tsx | 6 +- .../protocol/oidc/OIDCLoginProtocol.java | 4 +- 5 files changed, 8 insertions(+), 71 deletions(-) delete mode 100644 js/apps/account-ui/src/root/ErrorPage.tsx diff --git a/js/apps/account-ui/src/index.ts b/js/apps/account-ui/src/index.ts index 5d57ce5aee..adee82d589 100644 --- a/js/apps/account-ui/src/index.ts +++ b/js/apps/account-ui/src/index.ts @@ -1,5 +1,4 @@ export { PersonalInfo } from "./personal-info/PersonalInfo"; -export { ErrorPage } from "./root/ErrorPage"; export { Header } from "./root/Header"; export { PageNav } from "./root/PageNav"; export { DeviceActivity } from "./account-security/DeviceActivity"; diff --git a/js/apps/account-ui/src/root/ErrorPage.tsx b/js/apps/account-ui/src/root/ErrorPage.tsx deleted file mode 100644 index 97ee600e4a..0000000000 --- a/js/apps/account-ui/src/root/ErrorPage.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import { - Button, - Modal, - ModalVariant, - Page, - Text, - TextContent, - TextVariants, -} from "@patternfly/react-core"; -import { useTranslation } from "react-i18next"; -import { isRouteErrorResponse, useRouteError } from "react-router-dom"; - -type ErrorPageProps = { - error?: unknown; -}; - -export const ErrorPage = (props: ErrorPageProps) => { - const { t } = useTranslation(); - const error = useRouteError() ?? props.error; - const errorMessage = getErrorMessage(error); - - function onRetry() { - location.href = location.origin + location.pathname; - } - - return ( - - - {t("tryAgain")} - , - ]} - > - - {t("somethingWentWrongDescription")} - {errorMessage && ( - {errorMessage} - )} - - - - ); -}; - -function getErrorMessage(error: unknown): string | null { - if (typeof error === "string") { - return error; - } - - if (isRouteErrorResponse(error)) { - return error.statusText; - } - - if (error instanceof Error) { - return error.message; - } - - return null; -} diff --git a/js/apps/account-ui/src/routes.tsx b/js/apps/account-ui/src/routes.tsx index 3e549d6310..2b9fcb55c1 100644 --- a/js/apps/account-ui/src/routes.tsx +++ b/js/apps/account-ui/src/routes.tsx @@ -1,10 +1,9 @@ import { lazy } from "react"; import type { IndexRouteObject, RouteObject } from "react-router-dom"; - import { environment } from "./environment"; import { Organizations } from "./organizations/Organizations"; -import { ErrorPage } from "./root/ErrorPage"; import { Root } from "./root/Root"; +import { ErrorPage } from "@keycloak/keycloak-ui-shared"; const DeviceActivity = lazy(() => import("./account-security/DeviceActivity")); const LinkedAccounts = lazy(() => import("./account-security/LinkedAccounts")); diff --git a/js/libs/ui-shared/src/context/ErrorPage.tsx b/js/libs/ui-shared/src/context/ErrorPage.tsx index 6d66acedcd..af0babd843 100644 --- a/js/libs/ui-shared/src/context/ErrorPage.tsx +++ b/js/libs/ui-shared/src/context/ErrorPage.tsx @@ -8,6 +8,7 @@ import { TextVariants, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; +import { getNetworkErrorDescription } from "../utils/errors"; type ErrorPageProps = { error?: unknown; @@ -16,7 +17,10 @@ type ErrorPageProps = { export const ErrorPage = (props: ErrorPageProps) => { const { t } = useTranslation(); const error = props.error; - const errorMessage = getErrorMessage(error); + const errorMessage = + getErrorMessage(error) || + getNetworkErrorDescription(error)?.replace(/\+/g, " "); + console.error(error); function onRetry() { location.href = location.origin + location.pathname; diff --git a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java index 0bcae1ef42..7e6d26e93c 100755 --- a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java @@ -420,10 +420,10 @@ public class OIDCLoginProtocol implements LoginProtocol { case CANCELLED_AIA_SILENT: return new OAuth2ErrorRepresentation(null, null); case CANCELLED_AIA: - return new OAuth2ErrorRepresentation(OAuthErrorException.ACCESS_DENIED, "User cancelled aplication-initiated action."); + return new OAuth2ErrorRepresentation(OAuthErrorException.ACCESS_DENIED, "User cancelled application-initiated action."); case CANCELLED_BY_USER: case CONSENT_DENIED: - return new OAuth2ErrorRepresentation(OAuthErrorException.ACCESS_DENIED, null); + return new OAuth2ErrorRepresentation(OAuthErrorException.ACCESS_DENIED, "User denied consent"); case PASSIVE_INTERACTION_REQUIRED: return new OAuth2ErrorRepresentation(OAuthErrorException.INTERACTION_REQUIRED, null); case PASSIVE_LOGIN_REQUIRED: