initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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",
|
||||
response_type: "code",
|
||||
code_challenge: challenge,
|
||||
code_challenge_method: "S256",
|
||||
state,
|
||||
});
|
||||
|
||||
redirect(`${process.env.KOTOSOFT_ID_API_URL}/oauth/authorize?${params.toString()}`);
|
||||
}
|
||||
Reference in New Issue
Block a user