-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c45b423
commit 1a67e2e
Showing
7 changed files
with
138 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import configuration from "@/configuration"; | ||
import { returnUrlCookieName } from "@/lib/constant"; | ||
import { cookies } from "next/headers"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function POST() { | ||
const requestCookie = cookies(); | ||
const returnUrlCookie = requestCookie.get(returnUrlCookieName); | ||
const redirectUrl = returnUrlCookie?.value || configuration.appUrl; | ||
return NextResponse.redirect(redirectUrl); | ||
} |
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 |
---|---|---|
@@ -1,5 +1,64 @@ | ||
import { NextResponse } from "next/server"; | ||
import configuration from "@/configuration"; | ||
import { returnUrlCookieName } from "@/lib/constant"; | ||
import { setShortLiveCookie } from "@/lib/cookie"; | ||
import { prisma } from "@/lib/prisma"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function GET() { | ||
return NextResponse.json({}); | ||
export async function POST(request: NextRequest) { | ||
const body = (await request.json()) as { | ||
returnUrl?: string; | ||
idTokenHint?: string; | ||
clientId?: string; | ||
postLogoutRedirectUri?: string; | ||
state?: string; | ||
}; | ||
const { returnUrl, idTokenHint, clientId, postLogoutRedirectUri, state } = | ||
body; | ||
|
||
const wellKnownResponse = await fetch( | ||
`${configuration.portal.issuer}/.well-known/openid-configuration` | ||
); | ||
|
||
const wellKnown = (await wellKnownResponse.json()) as { | ||
issuer: string; | ||
authorization_endpoint: string; | ||
token_endpoint: string; | ||
userinfo_endpoint: string; | ||
end_session_endpoint: string; | ||
}; | ||
|
||
if (wellKnownResponse.status !== 200) { | ||
throw { code: wellKnownResponse.status, details: wellKnown }; | ||
} | ||
|
||
const params: { | ||
id_token_hint?: string; | ||
client_id?: string; | ||
post_logout_redirect_uri?: string; | ||
state?: string; | ||
} = { | ||
id_token_hint: idTokenHint, | ||
client_id: clientId, | ||
post_logout_redirect_uri: postLogoutRedirectUri, | ||
state: state, | ||
}; | ||
|
||
if (idTokenHint) { | ||
await prisma.session.updateMany({ | ||
where: { | ||
idToken: idTokenHint, | ||
}, | ||
data: { | ||
deletedAt: new Date(), | ||
}, | ||
}); | ||
} | ||
|
||
const endSessionUrl = `${ | ||
wellKnown.end_session_endpoint | ||
}?${new URLSearchParams(params).toString()}`; | ||
|
||
if (returnUrl) setShortLiveCookie(returnUrlCookieName, returnUrl); | ||
|
||
return NextResponse.json({ endSessionUrl }); | ||
} |
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,12 @@ | ||
import configuration from "@/configuration"; | ||
import { returnUrlCookieName } from "@/lib/constant"; | ||
import { cookies } from "next/headers"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default async function Page({ searchParams }: { searchParams: {} }) { | ||
console.log(`debug:searchParams`, searchParams); | ||
const requestCookie = cookies(); | ||
const returnUrlCookie = requestCookie.get(returnUrlCookieName); | ||
const redirectUrl = returnUrlCookie?.value || configuration.appUrl; | ||
return redirect(redirectUrl); | ||
} |
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