mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-13 11:40:16 +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") {
|
||||
return NextResponse.redirect(url);
|
||||
} else if (url && binding.case === "post") {
|
||||
// Create form data after SAML standard
|
||||
const formData = {
|
||||
RelayState: binding.value.relayState,
|
||||
SAMLResponse: binding.value.samlResponse,
|
||||
};
|
||||
|
||||
const formHtml = `
|
||||
<!DOCTYPE html>
|
||||
<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">
|
||||
${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>
|
||||
`;
|
||||
const redirectUrl = new URL(request.nextUrl.origin + "/saml-post");
|
||||
redirectUrl.searchParams.set("url", url);
|
||||
redirectUrl.searchParams.set("RelayState", formData.RelayState);
|
||||
redirectUrl.searchParams.set("SAMLResponse", formData.SAMLResponse);
|
||||
|
||||
// Return the HTML response
|
||||
return new NextResponse(formHtml, {
|
||||
headers: {
|
||||
"Content-Type": "text/html",
|
||||
},
|
||||
});
|
||||
return NextResponse.redirect(redirectUrl.toString());
|
||||
} else {
|
||||
console.log(
|
||||
"could not create response, redirect user to choose other account",
|
||||
|
Reference in New Issue
Block a user