From 0b7417a7887d463b30f70bdbe8f497b38f60eee1 Mon Sep 17 00:00:00 2001 From: Darren Clarke Date: Mon, 20 Jan 2025 11:25:13 +0100 Subject: [PATCH] Add Azure auth --- .../link/app/(login)/login/_components/Login.tsx | 16 ++++++++++++++++ apps/link/app/_lib/authentication.ts | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/apps/link/app/(login)/login/_components/Login.tsx b/apps/link/app/(login)/login/_components/Login.tsx index a1f57cb..0cc1234 100644 --- a/apps/link/app/(login)/login/_components/Login.tsx +++ b/apps/link/app/(login)/login/_components/Login.tsx @@ -12,6 +12,7 @@ import { import { Apple as AppleIcon, Google as GoogleIcon, + Microsoft as MicrosoftIcon, Key as KeyIcon, } from "@mui/icons-material"; import { signIn, getProviders } from "next-auth/react"; @@ -182,6 +183,21 @@ export const Login: FC = ({ session }) => { )} + {provider === "azure-ad" && ( + + + signIn("azure-ad", { + callbackUrl: `${origin}`, + }) + } + > + + Sign in with Azure + + + )} {provider === "credentials" && ( diff --git a/apps/link/app/_lib/authentication.ts b/apps/link/app/_lib/authentication.ts index b907e98..12ace5b 100644 --- a/apps/link/app/_lib/authentication.ts +++ b/apps/link/app/_lib/authentication.ts @@ -10,6 +10,7 @@ import { import Google from "next-auth/providers/google"; import Credentials from "next-auth/providers/credentials"; import Apple from "next-auth/providers/apple"; +import AzureADProvider from "next-auth/providers/azure-ad"; const headers = { Authorization: `Token ${process.env.ZAMMAD_API_TOKEN}` }; @@ -82,6 +83,18 @@ if (process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET) { clientSecret: process.env.APPLE_CLIENT_SECRET, }), ); +} else if ( + process.env.AZURE_AD_CLIENT_ID && + process.env.AZURE_AD_CLIENT_SECRET && + process.env.AZURE_AD_TENANT_ID +) { + providers.push( + AzureADProvider({ + clientId: process.env.AZURE_AD_CLIENT_ID, + clientSecret: process.env.AZURE_AD_CLIENT_SECRET, + tenantId: process.env.AZURE_AD_TENANT_ID, + }), + ); } else { providers.push( Credentials({