From cd51263428dd7d7dda4465e578bc9a06158f2062 Mon Sep 17 00:00:00 2001 From: Stavros Date: Thu, 11 Jun 2026 18:40:56 +0300 Subject: [PATCH] feat: add frontend --- frontend/src/lib/hooks/screen-params.ts | 2 + frontend/src/pages/authorize-page.tsx | 82 +++++++++++++++++-------- internal/bootstrap/router_bootstrap.go | 4 +- internal/bootstrap/service_bootstrap.go | 2 +- internal/controller/oauth_controller.go | 4 +- internal/controller/oidc_controller.go | 4 +- internal/service/auth_service.go | 4 +- internal/test/test.go | 4 +- 8 files changed, 71 insertions(+), 35 deletions(-) diff --git a/frontend/src/lib/hooks/screen-params.ts b/frontend/src/lib/hooks/screen-params.ts index 921fa4b6..d342d03a 100644 --- a/frontend/src/lib/hooks/screen-params.ts +++ b/frontend/src/lib/hooks/screen-params.ts @@ -6,6 +6,7 @@ type ScreenParams = { oidc_ticket?: string; oidc_scope?: string; oidc_name?: string; + oidc_show_consent?: boolean; }; const zodScreenParams = z.object({ @@ -14,6 +15,7 @@ const zodScreenParams = z.object({ oidc_ticket: z.string().optional(), oidc_scope: z.string().optional(), oidc_name: z.string().optional(), + oidc_show_consent: z.stringbool().optional(), }); export function useScreenParams(params: URLSearchParams): ScreenParams { diff --git a/frontend/src/pages/authorize-page.tsx b/frontend/src/pages/authorize-page.tsx index 3251c774..5f721217 100644 --- a/frontend/src/pages/authorize-page.tsx +++ b/frontend/src/pages/authorize-page.tsx @@ -25,6 +25,7 @@ import { recompileScreenParams, useScreenParams, } from "@/lib/hooks/screen-params"; +import { useEffect } from "react"; type Scope = { id: string; @@ -90,25 +91,48 @@ export const AuthorizePage = () => { const isOidc = screenParams.login_for === "oidc"; const compiledParams = recompileScreenParams(screenParams); - const authorizeMutation = useMutation({ - mutationFn: () => { - return axios.post("/api/oidc/authorize-complete", { - ticket: screenParams.oidc_ticket, - }); - }, - mutationKey: ["authorize", screenParams.oidc_ticket], - onSuccess: (data) => { - toast.info(t("authorizeSuccessTitle"), { - description: t("authorizeSuccessSubtitle"), - }); - window.location.replace(data.data.redirect_uri); - }, - onError: (error) => { - window.location.replace( - `/error?error=${encodeURIComponent(error.message)}`, - ); - }, - }); + const { mutate: authorizeMutate, isPending: authorizeIsPending } = + useMutation({ + mutationFn: () => { + return axios.post("/api/oidc/authorize-complete", { + ticket: screenParams.oidc_ticket, + }); + }, + mutationKey: ["authorize", screenParams.oidc_ticket], + onSuccess: (data) => { + toast.info(t("authorizeSuccessTitle"), { + description: t("authorizeSuccessSubtitle"), + }); + window.location.replace(data.data.redirect_uri); + }, + onError: (error) => { + window.location.replace( + `/error?error=${encodeURIComponent(error.message)}`, + ); + }, + }); + + useEffect(() => { + if ( + !isOidc || + screenParams.oidc_ticket === undefined || + screenParams.oidc_scope === undefined || + !auth.authenticated + ) { + return; + } + + if (screenParams.oidc_show_consent === false) { + authorizeMutate(); + } + }, [ + isOidc, + screenParams.oidc_ticket, + screenParams.oidc_scope, + screenParams.oidc_show_consent, + auth.authenticated, + authorizeMutate, + ]); if ( !isOidc || @@ -130,6 +154,19 @@ export const AuthorizePage = () => { const scopes = screenParams.oidc_scope.split(" ").filter((s) => s.trim() !== "") || []; + if (screenParams.oidc_show_consent === false) { + return ( + + + Authorizing + + You will soon be redirected to your application... + + + + ); + } + return ( @@ -171,15 +208,12 @@ export const AuthorizePage = () => { )} -