This commit is contained in:
Stavros
2025-08-31 01:11:18 +03:00
parent 17048d94b6
commit 4093a91e12
11 changed files with 117 additions and 54 deletions

View File

@@ -95,7 +95,6 @@ func init() {
{"generic-user-url", "", "Generic OAuth user info URL."}, {"generic-user-url", "", "Generic OAuth user info URL."},
{"generic-name", "Generic", "Generic OAuth provider name."}, {"generic-name", "Generic", "Generic OAuth provider name."},
{"generic-skip-ssl", false, "Skip SSL verification for the generic OAuth provider."}, {"generic-skip-ssl", false, "Skip SSL verification for the generic OAuth provider."},
{"disable-continue", false, "Disable continue screen and redirect to app directly."},
{"oauth-whitelist", "", "Comma separated list of email addresses to whitelist when using OAuth."}, {"oauth-whitelist", "", "Comma separated list of email addresses to whitelist when using OAuth."},
{"oauth-auto-redirect", "none", "Auto redirect to the specified OAuth provider if configured. (available providers: github, google, generic)"}, {"oauth-auto-redirect", "none", "Auto redirect to the specified OAuth provider if configured. (available providers: github, google, generic)"},
{"session-expiry", 86400, "Session (cookie) expiration time in seconds."}, {"session-expiry", 86400, "Session (cookie) expiration time in seconds."},

View File

@@ -0,0 +1,36 @@
import {
Card,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "../ui/card";
import { Button } from "../ui/button";
interface Props {
onClick: () => void;
appUrl: string;
currentUrl: string;
}
export const DomainWarning = (props: Props) => {
const { onClick, appUrl, currentUrl } = props;
return (
<Card className="min-w-xs sm:min-w-sm">
<CardHeader>
<CardTitle className="text-3xl">Incorrect Domain</CardTitle>
<CardDescription>
This instance is configured to be accessed from <code>{appUrl}</code>,
but <code>{currentUrl}</code> is being used. Authentication will most
likely fail if you proceed.
</CardDescription>
</CardHeader>
<CardFooter className="flex flex-col items-stretch">
<Button onClick={onClick} variant="warning">
Continue
</Button>
</CardFooter>
</Card>
);
};

View File

@@ -1,9 +1,13 @@
import { useAppContext } from "@/context/app-context"; import { useAppContext } from "@/context/app-context";
import { LanguageSelector } from "../language/language"; import { LanguageSelector } from "../language/language";
import { Outlet } from "react-router"; import { Outlet } from "react-router";
import { useState } from "react";
import { DomainWarning } from "../domain-warning/domain-warning";
export const Layout = () => { export const Layout = () => {
const { backgroundImage } = useAppContext(); const { backgroundImage, appUrl } = useAppContext();
const [ignoreDomainWarning, setIgnoreDomainWarning] = useState(false);
const currentUrl = window.location.origin;
return ( return (
<div <div
@@ -15,7 +19,15 @@ export const Layout = () => {
}} }}
> >
<LanguageSelector /> <LanguageSelector />
<Outlet /> {appUrl !== currentUrl && !ignoreDomainWarning ? (
<DomainWarning
onClick={() => setIgnoreDomainWarning(true)}
appUrl={appUrl}
currentUrl={currentUrl}
/>
) : (
<Outlet />
)}
</div> </div>
); );
}; };

View File

@@ -22,7 +22,7 @@ const buttonVariants = cva(
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50", "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
link: "text-primary underline-offset-4 hover:underline", link: "text-primary underline-offset-4 hover:underline",
warning: warning:
"bg-amber-500 text-white shadow-xs hover:bg-amber-400 focus-visible:ring-amber-200/20 dark:focus-visible:ring-amber-400/40 dark:bg-amber-600", "bg-amber-500 text-white shadow-xs hover:bg-amber-400 focus-visible:ring-amber-200/20 dark:focus-visible:ring-amber-400/40",
}, },
size: { size: {
default: "h-9 px-4 py-2 has-[>svg]:px-3", default: "h-9 px-4 py-2 has-[>svg]:px-3",

View File

@@ -20,8 +20,7 @@
"continueInvalidRedirectSubtitle": "The redirect URL is invalid", "continueInvalidRedirectSubtitle": "The redirect URL is invalid",
"continueInsecureRedirectTitle": "Insecure redirect", "continueInsecureRedirectTitle": "Insecure redirect",
"continueInsecureRedirectSubtitle": "You are trying to redirect from <code>https</code> to <code>http</code> which is not secure. Are you sure you want to continue?", "continueInsecureRedirectSubtitle": "You are trying to redirect from <code>https</code> to <code>http</code> which is not secure. Are you sure you want to continue?",
"continueTitle": "Continue", "continueRedirectManually": "Redirect me manually",
"continueSubtitle": "Click the button to continue to your app.",
"logoutFailTitle": "Failed to log out", "logoutFailTitle": "Failed to log out",
"logoutFailSubtitle": "Please try again", "logoutFailSubtitle": "Please try again",
"logoutSuccessTitle": "Logged out", "logoutSuccessTitle": "Logged out",
@@ -45,7 +44,7 @@
"unauthorizedIpSubtitle": "Your IP address <code>{{ip}}</code> is not authorized to access the resource <code>{{resource}}</code>.", "unauthorizedIpSubtitle": "Your IP address <code>{{ip}}</code> is not authorized to access the resource <code>{{resource}}</code>.",
"unauthorizedButton": "Try again", "unauthorizedButton": "Try again",
"untrustedRedirectTitle": "Untrusted redirect", "untrustedRedirectTitle": "Untrusted redirect",
"untrustedRedirectSubtitle": "You are trying to redirect to a domain that does not match your configured domain (<code>{{domain}}</code>). Are you sure you want to continue?", "untrustedRedirectSubtitle": "You are trying to redirect to a domain that does not match your configured domain (<code>{{rootDomain}}</code>). Are you sure you want to continue?",
"cancelTitle": "Cancel", "cancelTitle": "Cancel",
"forgotPasswordTitle": "Forgot your password?", "forgotPasswordTitle": "Forgot your password?",
"failedToFetchProvidersTitle": "Failed to load authentication providers. Please check your configuration.", "failedToFetchProvidersTitle": "Failed to load authentication providers. Please check your configuration.",

View File

@@ -20,8 +20,7 @@
"continueInvalidRedirectSubtitle": "The redirect URL is invalid", "continueInvalidRedirectSubtitle": "The redirect URL is invalid",
"continueInsecureRedirectTitle": "Insecure redirect", "continueInsecureRedirectTitle": "Insecure redirect",
"continueInsecureRedirectSubtitle": "You are trying to redirect from <code>https</code> to <code>http</code> which is not secure. Are you sure you want to continue?", "continueInsecureRedirectSubtitle": "You are trying to redirect from <code>https</code> to <code>http</code> which is not secure. Are you sure you want to continue?",
"continueTitle": "Continue", "continueRedirectManually": "Redirect me manually",
"continueSubtitle": "Click the button to continue to your app.",
"logoutFailTitle": "Failed to log out", "logoutFailTitle": "Failed to log out",
"logoutFailSubtitle": "Please try again", "logoutFailSubtitle": "Please try again",
"logoutSuccessTitle": "Logged out", "logoutSuccessTitle": "Logged out",
@@ -45,7 +44,7 @@
"unauthorizedIpSubtitle": "Your IP address <code>{{ip}}</code> is not authorized to access the resource <code>{{resource}}</code>.", "unauthorizedIpSubtitle": "Your IP address <code>{{ip}}</code> is not authorized to access the resource <code>{{resource}}</code>.",
"unauthorizedButton": "Try again", "unauthorizedButton": "Try again",
"untrustedRedirectTitle": "Untrusted redirect", "untrustedRedirectTitle": "Untrusted redirect",
"untrustedRedirectSubtitle": "You are trying to redirect to a domain that does not match your configured domain (<code>{{domain}}</code>). Are you sure you want to continue?", "untrustedRedirectSubtitle": "You are trying to redirect to a domain that does not match your configured domain (<code>{{rootDomain}}</code>). Are you sure you want to continue?",
"cancelTitle": "Cancel", "cancelTitle": "Cancel",
"forgotPasswordTitle": "Forgot your password?", "forgotPasswordTitle": "Forgot your password?",
"failedToFetchProvidersTitle": "Failed to load authentication providers. Please check your configuration.", "failedToFetchProvidersTitle": "Failed to load authentication providers. Please check your configuration.",

View File

@@ -12,7 +12,7 @@ import { isValidUrl } from "@/lib/utils";
import { Trans, useTranslation } from "react-i18next"; import { Trans, useTranslation } from "react-i18next";
import { Navigate, useLocation, useNavigate } from "react-router"; import { Navigate, useLocation, useNavigate } from "react-router";
import DOMPurify from "dompurify"; import DOMPurify from "dompurify";
import { useState } from "react"; import { useEffect, useState } from "react";
export const ContinuePage = () => { export const ContinuePage = () => {
const { isLoggedIn } = useUserContext(); const { isLoggedIn } = useUserContext();
@@ -21,9 +21,10 @@ export const ContinuePage = () => {
return <Navigate to="/login" />; return <Navigate to="/login" />;
} }
const { domain, disableContinue } = useAppContext(); const { rootDomain } = useAppContext();
const { search } = useLocation(); const { search } = useLocation();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [showRedirectButton, setShowRedirectButton] = useState(false);
const searchParams = new URLSearchParams(search); const searchParams = new URLSearchParams(search);
const redirectURI = searchParams.get("redirect_uri"); const redirectURI = searchParams.get("redirect_uri");
@@ -36,21 +37,20 @@ export const ContinuePage = () => {
return <Navigate to="/logout" />; return <Navigate to="/logout" />;
} }
const handleRedirect = () => {
setLoading(true);
window.location.href = DOMPurify.sanitize(redirectURI);
}
if (disableContinue) {
handleRedirect();
}
const { t } = useTranslation(); const { t } = useTranslation();
const navigate = useNavigate(); const navigate = useNavigate();
const url = new URL(redirectURI); const handleRedirect = () => {
setLoading(true);
window.location.href = DOMPurify.sanitize(redirectURI);
};
if (!(url.hostname == domain) && !url.hostname.endsWith(`.${domain}`)) { const redirectURLObj = new URL(redirectURI);
if (
!(redirectURLObj.hostname == rootDomain) &&
!redirectURLObj.hostname.endsWith(`.${rootDomain}`)
) {
return ( return (
<Card className="min-w-xs sm:min-w-sm"> <Card className="min-w-xs sm:min-w-sm">
<CardHeader> <CardHeader>
@@ -64,7 +64,7 @@ export const ContinuePage = () => {
components={{ components={{
code: <code />, code: <code />,
}} }}
values={{ domain }} values={{ rootDomain }}
/> />
</CardDescription> </CardDescription>
</CardHeader> </CardHeader>
@@ -76,7 +76,11 @@ export const ContinuePage = () => {
> >
{t("continueTitle")} {t("continueTitle")}
</Button> </Button>
<Button onClick={() => navigate("/logout")} variant="outline" disabled={loading}> <Button
onClick={() => navigate("/logout")}
variant="outline"
disabled={loading}
>
{t("cancelTitle")} {t("cancelTitle")}
</Button> </Button>
</CardFooter> </CardFooter>
@@ -84,7 +88,10 @@ export const ContinuePage = () => {
); );
} }
if (url.protocol === "http:" && window.location.protocol === "https:") { if (
redirectURLObj.protocol === "http:" &&
window.location.protocol === "https:"
) {
return ( return (
<Card className="min-w-xs sm:min-w-sm"> <Card className="min-w-xs sm:min-w-sm">
<CardHeader> <CardHeader>
@@ -102,14 +109,14 @@ export const ContinuePage = () => {
</CardDescription> </CardDescription>
</CardHeader> </CardHeader>
<CardFooter className="flex flex-col items-stretch gap-2"> <CardFooter className="flex flex-col items-stretch gap-2">
<Button <Button onClick={handleRedirect} loading={loading} variant="warning">
onClick={handleRedirect}
loading={loading}
variant="warning"
>
{t("continueTitle")} {t("continueTitle")}
</Button> </Button>
<Button onClick={() => navigate("/logout")} variant="outline" disabled={loading}> <Button
onClick={() => navigate("/logout")}
variant="outline"
disabled={loading}
>
{t("cancelTitle")} {t("cancelTitle")}
</Button> </Button>
</CardFooter> </CardFooter>
@@ -117,20 +124,31 @@ export const ContinuePage = () => {
); );
} }
useEffect(() => {
setTimeout(() => {
handleRedirect();
}, 100);
setTimeout(() => {
setLoading(false);
setShowRedirectButton(true);
}, 1000);
}, []);
return ( return (
<Card className="min-w-xs sm:min-w-sm"> <Card className="min-w-xs sm:min-w-sm">
<CardHeader> <CardHeader>
<CardTitle className="text-3xl">{t("continueTitle")}</CardTitle> <CardTitle className="text-3xl">
<CardDescription>{t("continueSubtitle")}</CardDescription> {t("continueRedirectingTitle")}
</CardTitle>
<CardDescription>{t("continueRedirectingSubtitle")}</CardDescription>
</CardHeader> </CardHeader>
<CardFooter className="flex flex-col items-stretch"> {showRedirectButton && (
<Button <CardFooter className="flex flex-col items-stretch">
onClick={handleRedirect} <Button onClick={handleRedirect}>
loading={loading} {t("continueRedirectManually")}
> </Button>
{t("continueTitle")} </CardFooter>
</Button> )}
</CardFooter>
</Card> </Card>
); );
}; };

View File

@@ -2,10 +2,10 @@ import { z } from "zod";
export const appContextSchema = z.object({ export const appContextSchema = z.object({
configuredProviders: z.array(z.string()), configuredProviders: z.array(z.string()),
disableContinue: z.boolean(),
title: z.string(), title: z.string(),
genericName: z.string(), genericName: z.string(),
domain: z.string(), appUrl: z.string(),
rootDomain: z.string(),
forgotPasswordMessage: z.string(), forgotPasswordMessage: z.string(),
oauthAutoRedirect: z.enum(["none", "github", "google", "generic"]), oauthAutoRedirect: z.enum(["none", "github", "google", "generic"]),
backgroundImage: z.string(), backgroundImage: z.string(),

View File

@@ -177,10 +177,10 @@ func (app *BootstrapApp) Setup() error {
// Create controllers // Create controllers
contextController := controller.NewContextController(controller.ContextControllerConfig{ contextController := controller.NewContextController(controller.ContextControllerConfig{
ConfiguredProviders: configuredProviders, ConfiguredProviders: configuredProviders,
DisableContinue: app.Config.DisableContinue,
Title: app.Config.Title, Title: app.Config.Title,
GenericName: app.Config.GenericName, GenericName: app.Config.GenericName,
Domain: domain, AppURL: app.Config.AppURL,
RootDomain: domain,
ForgotPasswordMessage: app.Config.ForgotPasswordMessage, ForgotPasswordMessage: app.Config.ForgotPasswordMessage,
BackgroundImage: app.Config.BackgroundImage, BackgroundImage: app.Config.BackgroundImage,
OAuthAutoRedirect: app.Config.OAuthAutoRedirect, OAuthAutoRedirect: app.Config.OAuthAutoRedirect,

View File

@@ -36,7 +36,6 @@ type Config struct {
GenericUserURL string `mapstructure:"generic-user-url"` GenericUserURL string `mapstructure:"generic-user-url"`
GenericName string `mapstructure:"generic-name"` GenericName string `mapstructure:"generic-name"`
GenericSkipSSL bool `mapstructure:"generic-skip-ssl"` GenericSkipSSL bool `mapstructure:"generic-skip-ssl"`
DisableContinue bool `mapstructure:"disable-continue"`
OAuthWhitelist string `mapstructure:"oauth-whitelist"` OAuthWhitelist string `mapstructure:"oauth-whitelist"`
OAuthAutoRedirect string `mapstructure:"oauth-auto-redirect" validate:"oneof=none github google generic"` OAuthAutoRedirect string `mapstructure:"oauth-auto-redirect" validate:"oneof=none github google generic"`
SessionExpiry int `mapstructure:"session-expiry"` SessionExpiry int `mapstructure:"session-expiry"`

View File

@@ -15,7 +15,7 @@ type UserContextResponse struct {
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
Provider string `json:"provider"` Provider string `json:"provider"`
Oauth bool `json:"oauth"` OAuth bool `json:"oauth"`
TotpPending bool `json:"totpPending"` TotpPending bool `json:"totpPending"`
} }
@@ -23,10 +23,10 @@ type AppContextResponse struct {
Status int `json:"status"` Status int `json:"status"`
Message string `json:"message"` Message string `json:"message"`
ConfiguredProviders []string `json:"configuredProviders"` ConfiguredProviders []string `json:"configuredProviders"`
DisableContinue bool `json:"disableContinue"`
Title string `json:"title"` Title string `json:"title"`
GenericName string `json:"genericName"` GenericName string `json:"genericName"`
Domain string `json:"domain"` AppURL string `json:"appUrl"`
RootDomain string `json:"rootDomain"`
ForgotPasswordMessage string `json:"forgotPasswordMessage"` ForgotPasswordMessage string `json:"forgotPasswordMessage"`
BackgroundImage string `json:"backgroundImage"` BackgroundImage string `json:"backgroundImage"`
OAuthAutoRedirect string `json:"oauthAutoRedirect"` OAuthAutoRedirect string `json:"oauthAutoRedirect"`
@@ -37,7 +37,8 @@ type ContextControllerConfig struct {
DisableContinue bool DisableContinue bool
Title string Title string
GenericName string GenericName string
Domain string AppURL string
RootDomain string
ForgotPasswordMessage string ForgotPasswordMessage string
BackgroundImage string BackgroundImage string
OAuthAutoRedirect string OAuthAutoRedirect string
@@ -72,7 +73,7 @@ func (controller *ContextController) userContextHandler(c *gin.Context) {
Name: context.Name, Name: context.Name,
Email: context.Email, Email: context.Email,
Provider: context.Provider, Provider: context.Provider,
Oauth: context.OAuth, OAuth: context.OAuth,
TotpPending: context.TotpPending, TotpPending: context.TotpPending,
} }
@@ -93,10 +94,10 @@ func (controller *ContextController) appContextHandler(c *gin.Context) {
Status: 200, Status: 200,
Message: "Success", Message: "Success",
ConfiguredProviders: controller.Config.ConfiguredProviders, ConfiguredProviders: controller.Config.ConfiguredProviders,
DisableContinue: controller.Config.DisableContinue,
Title: controller.Config.Title, Title: controller.Config.Title,
GenericName: controller.Config.GenericName, GenericName: controller.Config.GenericName,
Domain: controller.Config.Domain, AppURL: controller.Config.AppURL,
RootDomain: controller.Config.RootDomain,
ForgotPasswordMessage: controller.Config.ForgotPasswordMessage, ForgotPasswordMessage: controller.Config.ForgotPasswordMessage,
BackgroundImage: controller.Config.BackgroundImage, BackgroundImage: controller.Config.BackgroundImage,
OAuthAutoRedirect: controller.Config.OAuthAutoRedirect, OAuthAutoRedirect: controller.Config.OAuthAutoRedirect,