From 76c1c40e7471d567e27f87c1136988ddf41224d7 Mon Sep 17 00:00:00 2001 From: gibbyb Date: Wed, 15 Jan 2025 16:41:21 -0600 Subject: [PATCH] Add authentik --- next.config.js | 0 scripts/next.config.default.js | 37 +++++++++++++++++++ src/auth.ts | 6 +++ .../auth/client/{ => authentik}/Sign_In.tsx | 4 +- .../auth/client/microsoft/Sign_In.tsx | 15 ++++++++ .../auth/server/authentik/Sign_In.tsx | 21 +++++++++++ .../auth/server/{ => microsoft}/Sign_In.tsx | 2 +- src/components/ui/No_Session.tsx | 8 +++- 8 files changed, 88 insertions(+), 5 deletions(-) mode change 100755 => 100644 next.config.js rename src/components/auth/client/{ => authentik}/Sign_In.tsx (82%) create mode 100755 src/components/auth/client/microsoft/Sign_In.tsx create mode 100755 src/components/auth/server/authentik/Sign_In.tsx rename src/components/auth/server/{ => microsoft}/Sign_In.tsx (93%) diff --git a/next.config.js b/next.config.js old mode 100755 new mode 100644 diff --git a/scripts/next.config.default.js b/scripts/next.config.default.js index ffbf3fa..1d2bbfb 100644 --- a/scripts/next.config.default.js +++ b/scripts/next.config.default.js @@ -10,4 +10,41 @@ const config = { }; export default config; +/** + * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful + * for Docker builds. + */ +//await import("./src/env.js"); + +//const cspHeader = ` + //default-src 'self'; + //script-src 'self' 'unsafe-eval' 'unsafe-inline'; + //style-src 'self' 'unsafe-inline'; + //img-src 'self' blob: data:; + //font-src 'self'; + //object-src 'none'; + //base-uri 'self'; + //form-action 'self'; + //frame-ancestors 'none'; + //upgrade-insecure-requests; +//` + +//[>* @type {import("next").NextConfig} <] +//const config = { + //async headers() { + //return [ + //{ + //source: "/(.*)", + //headers: [ + //{ + //key: "Content-Security-Policy", + //value: cspHeader.replace(/\n/g, ''), + //}, + //], + //}, + //]; + //}, +//}; + +//export default config; diff --git a/src/auth.ts b/src/auth.ts index 6cda898..e732085 100755 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,5 +1,6 @@ import NextAuth from "next-auth" import Entra from "next-auth/providers/microsoft-entra-id" +import Authentik from "next-auth/providers/authentik" export const { handlers, auth, signIn, signOut } = NextAuth({ providers: [ @@ -8,5 +9,10 @@ export const { handlers, auth, signIn, signOut } = NextAuth({ clientSecret: process.env.AUTH_MICROSOFT_ENTRA_ID_SECRET, tenantId: process.env.AUTH_MICROSOFT_ENTRA_ID_TENANT_ID, }), + Authentik({ + clientId: process.env.AUTH_AUTHENTIK_CLIENT_ID, + clientSecret: process.env.AUTH_AUTHENTIK_CLIENT_SECRET, + issuer: process.env.AUTH_AUTHENTIK_ISSUER, + }), ], }) diff --git a/src/components/auth/client/Sign_In.tsx b/src/components/auth/client/authentik/Sign_In.tsx similarity index 82% rename from src/components/auth/client/Sign_In.tsx rename to src/components/auth/client/authentik/Sign_In.tsx index c7624ef..cedd837 100755 --- a/src/components/auth/client/Sign_In.tsx +++ b/src/components/auth/client/authentik/Sign_In.tsx @@ -1,10 +1,10 @@ import { signIn } from "next-auth/react"; import { Button } from "~/components/ui/shadcn/button"; -export default function Sign_In() { +export default function Sign_In_Authentik() { return ( + ); +}; diff --git a/src/components/auth/server/authentik/Sign_In.tsx b/src/components/auth/server/authentik/Sign_In.tsx new file mode 100755 index 0000000..6ba40f4 --- /dev/null +++ b/src/components/auth/server/authentik/Sign_In.tsx @@ -0,0 +1,21 @@ +import Image from "next/image"; +import { signIn } from "~/auth"; + +export default async function Sign_In_Authentik() { + return ( +
{ + "use server"; + await signIn("authentik"); + }}> + +
+ ); +} diff --git a/src/components/auth/server/Sign_In.tsx b/src/components/auth/server/microsoft/Sign_In.tsx similarity index 93% rename from src/components/auth/server/Sign_In.tsx rename to src/components/auth/server/microsoft/Sign_In.tsx index 710a8c0..842f558 100755 --- a/src/components/auth/server/Sign_In.tsx +++ b/src/components/auth/server/microsoft/Sign_In.tsx @@ -1,7 +1,7 @@ import Image from "next/image"; import { signIn } from "~/auth"; -export default async function Sign_In() { +export default async function Sign_In_Microsoft() { return (
{ diff --git a/src/components/ui/No_Session.tsx b/src/components/ui/No_Session.tsx index 1d7af13..92b3756 100755 --- a/src/components/ui/No_Session.tsx +++ b/src/components/ui/No_Session.tsx @@ -1,6 +1,7 @@ import Link from "next/link"; import Image from "next/image"; -import Sign_In from "~/components/auth/server/Sign_In"; +import Sign_In_Microsoft from "~/components/auth/server/microsoft/Sign_In"; +import Sign_In_Authentik from "~/components/auth/server/authentik/Sign_In"; import Header from "~/components/ui/Header"; export default function No_Session() { @@ -12,7 +13,10 @@ export default function No_Session() {
- < Sign_In /> + < Sign_In_Microsoft /> +
+
+ < Sign_In_Authentik />