31 lines
786 B
TypeScript
31 lines
786 B
TypeScript
import { generateState, generateCodeVerifier } from "arctic";
|
|
import { authentik } from "$lib/server/oauth";
|
|
|
|
import type { RequestEvent } from "@sveltejs/kit";
|
|
|
|
export async function GET(event: RequestEvent): Promise<Response> {
|
|
const state = generateState();
|
|
const codeVerifier = generateCodeVerifier();
|
|
const url = authentik.createAuthorizationURL(state, codeVerifier, ["openid", "profile"]);
|
|
|
|
event.cookies.set("authentik_oauth_state", state, {
|
|
path: "/",
|
|
httpOnly: true,
|
|
maxAge: 60 * 10, // 10 minutes
|
|
sameSite: "lax"
|
|
});
|
|
event.cookies.set("authentik_code_verifier", codeVerifier, {
|
|
path: "/",
|
|
httpOnly: true,
|
|
maxAge: 60 * 10, // 10 minutes
|
|
sameSite: "lax"
|
|
});
|
|
|
|
return new Response(null, {
|
|
status: 302,
|
|
headers: {
|
|
Location: url.toString()
|
|
}
|
|
});
|
|
}
|