mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-13 14:30:00 +00:00
fix: seperate route
This commit is contained in:
45
apps/login/src/app/(login)/saml-post/page.tsx
Normal file
45
apps/login/src/app/(login)/saml-post/page.tsx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useSearchParams } from "next/navigation";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
export default function SamlPost() {
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const url = searchParams.get("url");
|
||||||
|
const relayState = searchParams.get("RelayState");
|
||||||
|
const samlResponse = searchParams.get("SAMLResponse");
|
||||||
|
|
||||||
|
console.log(relayState, samlResponse);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Automatically submit the form after rendering
|
||||||
|
const form = document.getElementById("samlForm") as HTMLFormElement;
|
||||||
|
if (form) {
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!url || !relayState || !samlResponse) {
|
||||||
|
return (
|
||||||
|
<p className="text-center">Missing required parameters for SAML POST.</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charSet="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Redirecting...</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form id="samlForm" action={url} method="POST">
|
||||||
|
<input type="hidden" name="RelayState" value={relayState} />
|
||||||
|
<input type="hidden" name="SAMLResponse" value={samlResponse} />
|
||||||
|
</form>
|
||||||
|
<p>Redirecting...</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
@@ -473,43 +473,17 @@ export async function GET(request: NextRequest) {
|
|||||||
if (url && binding.case === "redirect") {
|
if (url && binding.case === "redirect") {
|
||||||
return NextResponse.redirect(url);
|
return NextResponse.redirect(url);
|
||||||
} else if (url && binding.case === "post") {
|
} else if (url && binding.case === "post") {
|
||||||
// Create form data after SAML standard
|
|
||||||
const formData = {
|
const formData = {
|
||||||
RelayState: binding.value.relayState,
|
RelayState: binding.value.relayState,
|
||||||
SAMLResponse: binding.value.samlResponse,
|
SAMLResponse: binding.value.samlResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
const formHtml = `
|
const redirectUrl = new URL(request.nextUrl.origin + "/saml-post");
|
||||||
<!DOCTYPE html>
|
redirectUrl.searchParams.set("url", url);
|
||||||
<html lang="en">
|
redirectUrl.searchParams.set("RelayState", formData.RelayState);
|
||||||
<head>
|
redirectUrl.searchParams.set("SAMLResponse", formData.SAMLResponse);
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Redirecting...</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<form id="samlForm" action="${url}" method="POST">
|
|
||||||
${Object.entries(formData)
|
|
||||||
.map(
|
|
||||||
([key, value]) =>
|
|
||||||
`<input type="hidden" name="${key}" value="${value}" />`,
|
|
||||||
)
|
|
||||||
.join("\n")}
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
// Automatically submit the form
|
|
||||||
document.getElementById('samlForm').submit();
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Return the HTML response
|
return NextResponse.redirect(redirectUrl.toString());
|
||||||
return new NextResponse(formHtml, {
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "text/html",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
"could not create response, redirect user to choose other account",
|
"could not create response, redirect user to choose other account",
|
||||||
|
Reference in New Issue
Block a user