Add Azure auth

This commit is contained in:
Darren Clarke 2025-01-20 11:25:13 +01:00
parent c402000f12
commit 0b7417a788
2 changed files with 29 additions and 0 deletions

View file

@ -12,6 +12,7 @@ import {
import { import {
Apple as AppleIcon, Apple as AppleIcon,
Google as GoogleIcon, Google as GoogleIcon,
Microsoft as MicrosoftIcon,
Key as KeyIcon, Key as KeyIcon,
} from "@mui/icons-material"; } from "@mui/icons-material";
import { signIn, getProviders } from "next-auth/react"; import { signIn, getProviders } from "next-auth/react";
@ -182,6 +183,21 @@ export const Login: FC<LoginProps> = ({ session }) => {
</IconButton> </IconButton>
</Grid> </Grid>
)} )}
{provider === "azure-ad" && (
<Grid item sx={{ width: "100%" }}>
<IconButton
sx={buttonStyles}
onClick={() =>
signIn("azure-ad", {
callbackUrl: `${origin}`,
})
}
>
<MicrosoftIcon sx={{ mr: 1 }} />
Sign in with Azure
</IconButton>
</Grid>
)}
{provider === "credentials" && ( {provider === "credentials" && (
<Grid item container spacing={3}> <Grid item container spacing={3}>
<Grid item sx={{ width: "100%" }}> <Grid item sx={{ width: "100%" }}>

View file

@ -10,6 +10,7 @@ import {
import Google from "next-auth/providers/google"; import Google from "next-auth/providers/google";
import Credentials from "next-auth/providers/credentials"; import Credentials from "next-auth/providers/credentials";
import Apple from "next-auth/providers/apple"; import Apple from "next-auth/providers/apple";
import AzureADProvider from "next-auth/providers/azure-ad";
const headers = { Authorization: `Token ${process.env.ZAMMAD_API_TOKEN}` }; 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, 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 { } else {
providers.push( providers.push(
Credentials({ Credentials({