-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine): Add SAML SSO endpoints (#447)
Signed-off-by: Chris Lo <[email protected]> Co-authored-by: Daryl Lim <[email protected]>
- Loading branch information
1 parent
1695c38
commit 6adb896
Showing
23 changed files
with
581 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { NextRequest, NextResponse } from "next/server" | ||
|
||
import { buildUrl, getDomain } from "@/lib/ss-utils" | ||
|
||
/** | ||
* @param request | ||
* @returns | ||
*/ | ||
export async function POST(request: NextRequest) { | ||
console.log("POST /auth/saml/acs", request.nextUrl.toString()) | ||
|
||
// Parse the form data from the request | ||
const formData = await request.formData() | ||
const samlResponse = formData.get('SAMLResponse') | ||
|
||
if (!samlResponse) { | ||
console.error("No SAML response found in the request") | ||
return NextResponse.redirect(new URL("/auth/error", getDomain(request))) | ||
} | ||
|
||
// Prepare the request to the FastAPI backend | ||
const backendUrl = new URL(buildUrl("/auth/saml/acs")) | ||
const backendFormData = new FormData() | ||
backendFormData.append('SAMLResponse', samlResponse) | ||
|
||
// Forward the request to the FastAPI backend | ||
const backendResponse = await fetch(backendUrl.toString(), { | ||
method: 'POST', | ||
body: backendFormData, | ||
}) | ||
|
||
if (!backendResponse.ok) { | ||
console.error("Error from backend:", await backendResponse.text()) | ||
return NextResponse.redirect(new URL("/auth/error", getDomain(request))) | ||
} | ||
|
||
const setCookieHeader = backendResponse.headers.get("set-cookie") | ||
|
||
if (!setCookieHeader) { | ||
console.error("No set-cookie header found in response") | ||
return NextResponse.redirect(new URL("/auth/error", getDomain(request))) | ||
} | ||
|
||
console.log("Redirecting to / with GET") | ||
const redirectUrl = new URL("/", getDomain(request)) | ||
const redirectResponse = NextResponse.redirect(redirectUrl, { | ||
status: 303 // Force GET request | ||
}) | ||
redirectResponse.headers.set("set-cookie", setCookieHeader) | ||
return redirectResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.