26 lines
993 B
TypeScript
26 lines
993 B
TypeScript
import { cookies } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
import { pkceConfig } from "@/lib/cookie-config";
|
|
import crypto from "crypto";
|
|
|
|
export async function GET() {
|
|
const verifier = crypto.randomBytes(32).toString("base64url");
|
|
const challenge = crypto.createHash("sha256").update(verifier).digest("base64url");
|
|
const state = crypto.randomBytes(16).toString("hex");
|
|
|
|
const store = await cookies();
|
|
store.set("pkce_verifier", verifier, pkceConfig);
|
|
store.set("oauth_state", state, { ...pkceConfig, path: "/api/callback" });
|
|
|
|
const params = new URLSearchParams({
|
|
client_id: process.env.CLIENT_ID!,
|
|
redirect_uri: `${process.env.PUBLIC_URL}/api/callback`,
|
|
scope: "profile:read profile:edit profile:consent:read profile:consent:delete",
|
|
response_type: "code",
|
|
code_challenge: challenge,
|
|
code_challenge_method: "S256",
|
|
state,
|
|
});
|
|
|
|
redirect(`${process.env.KOTOSOFT_ID_API_PUBLIC_URL}/oauth/authorize?${params.toString()}`);
|
|
} |