mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-25 22:08:46 +00:00
Closes #11096 # Which Problems Are Solved This pull request resolves a 404 error that occurred at the end of the LDAP login flow. Previously, when a user submitted their LDAP credentials in the apps/login application, the form initiated the session creation process but incorrectly redirected the user to /idp/ldap/success, a route that does not exist. In addition, the redirect failed to preserve necessary IDP context parameters (such as requestId, organization, and linking fingerprint info) that are required to fully complete the authentication intent. # How the Problems Are Solved - Fixed redirect path: Updated `createNewSessionForLDAP` to redirect to `/idp/ldap/process` instead of success, aligning it with the standard IDP intent processing pipeline which dynamically resolves `[provider]/process`. - Preserved context parameters: Extracted `requestId`, `organization`, `postErrorRedirectUrl`, `linkToSessionId`, and `linkFingerprint` from the URL parameters on the LDAP page and passed them through LDAPUsernamePasswordForm down to the server action so the ongoing auth request is successfully tied to the user's intent.
132 lines
3.3 KiB
TypeScript
132 lines
3.3 KiB
TypeScript
"use client";
|
|
|
|
import { createNewSessionForLDAP } from "@/lib/server/idp";
|
|
import { useTranslations } from "next-intl";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState } from "react";
|
|
import { useForm } from "react-hook-form";
|
|
import { Alert } from "./alert";
|
|
import { BackButton } from "./back-button";
|
|
import { Button, ButtonVariants } from "./button";
|
|
import { TextInput } from "./input";
|
|
import { Spinner } from "./spinner";
|
|
import { Translated } from "./translated";
|
|
|
|
type Inputs = {
|
|
loginName: string;
|
|
password: string;
|
|
};
|
|
|
|
type Props = {
|
|
idpId: string;
|
|
link: boolean;
|
|
requestId?: string;
|
|
organization?: string;
|
|
postErrorRedirectUrl?: string;
|
|
linkToSessionId?: string;
|
|
linkFingerprint?: string;
|
|
};
|
|
|
|
export function LDAPUsernamePasswordForm({
|
|
idpId,
|
|
link,
|
|
requestId,
|
|
organization,
|
|
postErrorRedirectUrl,
|
|
linkToSessionId,
|
|
linkFingerprint,
|
|
}: Props) {
|
|
const { register, handleSubmit, formState } = useForm<Inputs>({
|
|
mode: "onChange",
|
|
});
|
|
|
|
const t = useTranslations("ldap");
|
|
|
|
const [error, setError] = useState<string>("");
|
|
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
|
|
const router = useRouter();
|
|
|
|
async function submitUsernamePassword(values: Inputs) {
|
|
setError("");
|
|
setLoading(true);
|
|
|
|
const response = await createNewSessionForLDAP({
|
|
idpId: idpId,
|
|
username: values.loginName,
|
|
password: values.password,
|
|
link: link,
|
|
requestId,
|
|
organization,
|
|
postErrorRedirectUrl,
|
|
linkToSessionId,
|
|
linkFingerprint,
|
|
})
|
|
.catch(() => {
|
|
setError("Could not start LDAP flow");
|
|
return;
|
|
})
|
|
.finally(() => {
|
|
setLoading(false);
|
|
});
|
|
|
|
if (response && "error" in response && response.error) {
|
|
setError(response.error);
|
|
return;
|
|
}
|
|
|
|
if (response && "redirect" in response && response.redirect) {
|
|
return router.push(response.redirect);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form className="w-full space-y-4">
|
|
<TextInput
|
|
type="text"
|
|
autoComplete="username"
|
|
autoCapitalize="none"
|
|
autoCorrect="off"
|
|
spellCheck={false}
|
|
autoFocus
|
|
{...register("loginName", { required: t("required.username") })}
|
|
label={t("labels.username")}
|
|
data-testid="username-text-input"
|
|
/>
|
|
|
|
<div className={`${error && "transform-gpu animate-shake"}`}>
|
|
<TextInput
|
|
type="password"
|
|
autoComplete="password"
|
|
{...register("password", { required: t("required.password") })}
|
|
label={t("labels.password")}
|
|
data-testid="password-text-input"
|
|
/>
|
|
</div>
|
|
|
|
{error && (
|
|
<div className="py-4" data-testid="error">
|
|
<Alert>{error}</Alert>
|
|
</div>
|
|
)}
|
|
|
|
<div className="mt-8 flex w-full flex-row items-center">
|
|
<BackButton data-testid="back-button" />
|
|
<span className="flex-grow"></span>
|
|
<Button
|
|
type="submit"
|
|
className="self-end"
|
|
variant={ButtonVariants.Primary}
|
|
disabled={loading || !formState.isValid}
|
|
onClick={handleSubmit(submitUsernamePassword)}
|
|
data-testid="submit-button"
|
|
>
|
|
{loading && <Spinner className="mr-2 h-5 w-5" />}
|
|
<Translated i18nKey="submit" namespace="ldap" />
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|