Desktop oAuth integration

Co-authored-by: RagingLightning <RagingLightningCode@gmail.com>
This commit is contained in:
PxlLoewe
2025-05-09 08:36:01 -07:00
parent 1948d34963
commit 654bdfbbaa
8 changed files with 95 additions and 62 deletions

View File

@@ -1,4 +1,5 @@
"use server";
import { generateUUID } from "../../../../helper/uuid";
import { getServerSession } from "../../../api/auth/[...nextauth]/auth";
import { Service } from "../page";
import { PrismaClient } from "@repo/db";
@@ -9,15 +10,7 @@ export const generateToken = async (service: Service) => {
const session = await getServerSession();
if (!session) return null;
const key = await crypto.subtle.generateKey(
{ name: "HMAC", hash: "SHA-256" },
true,
["sign"],
);
const exportedKey = await crypto.subtle.exportKey("raw", key);
const accessToken = Array.from(new Uint8Array(exportedKey))
.map((byte) => byte.toString(16).padStart(2, "0"))
.join("");
const accessToken = generateUUID(16);
const code = await prisma.oAuthToken.create({
data: {

View File

@@ -9,9 +9,10 @@ export const services = [
},
{
id: "2",
secret: "jp2k430fnv",
service: "desktop",
name: "Desktop client",
approvedUrls: ["var"],
approvedUrls: ["var://oAuth"],
},
{
id: "3",
@@ -26,7 +27,7 @@ export const services = [
];
export type Service = (typeof services)[number];
export default async ({
const Page = async ({
searchParams,
}: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
@@ -43,3 +44,5 @@ export default async ({
return <Authorize service={service} />;
};
export default Page;