From 4559df9e8be5a120f36b3e1450f1d0a8e7422329 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 10 Sep 2024 03:40:10 +0100 Subject: [PATCH] ms login working --- src/app/api/auth/[...nextauth]/route.ts | 19 +++++++++++-------- .../signin/MicrosoftSignInButton.jsx | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 96517f0c..b6aea4e4 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,15 +1,16 @@ import NextAuth, { NextAuthOptions } from "next-auth"; import GoogleProvider from "next-auth/providers/google"; -import AzureADProvider from "next-auth/providers/azure-ad"; +import AzureADB2CProvider from "next-auth/providers/azure-ad-b2c"; import { db } from "@/app/db/db"; import { user as userTable, User } from "@/app/db/schema/users"; import { eq } from "drizzle-orm"; const { GOOGLE_CLIENT_ID = "", GOOGLE_CLIENT_SECRET = "" } = process.env; const { - AZURE_AD_CLIENT_ID = "", - AZURE_AD_CLIENT_SECRET = "", - AZURE_AD_TENANT_ID = "", + AZURE_AD_B2C_TENANT_NAME = "", + AZURE_AD_B2C_CLIENT_ID = "", + AZURE_AD_B2C_CLIENT_SECRET = "", + AZURE_AD_B2C_PRIMARY_USER_FLOW = "", } = process.env; type OauthProvider = "google"; @@ -32,12 +33,14 @@ export const AuthOptions: NextAuthOptions = { }, }, }), - AzureADProvider({ - clientId: AZURE_AD_CLIENT_ID, - clientSecret: AZURE_AD_CLIENT_SECRET, - tenantId: AZURE_AD_TENANT_ID, + AzureADB2CProvider({ + tenantId: AZURE_AD_B2C_TENANT_NAME, + clientId: AZURE_AD_B2C_CLIENT_ID, + clientSecret: AZURE_AD_B2C_CLIENT_SECRET, + primaryUserFlow: AZURE_AD_B2C_PRIMARY_USER_FLOW, authorization: { params: { + scope: `https://${process.env.AZURE_AD_B2C_TENANT_NAME}.onmicrosoft.com/api/demo.read https://${process.env.AZURE_AD_B2C_TENANT_NAME}.onmicrosoft.com/api/demo.write offline_access openid`, prompt: "consent", }, }, diff --git a/src/app/components/signin/MicrosoftSignInButton.jsx b/src/app/components/signin/MicrosoftSignInButton.jsx index bb881fd3..f53399f4 100644 --- a/src/app/components/signin/MicrosoftSignInButton.jsx +++ b/src/app/components/signin/MicrosoftSignInButton.jsx @@ -13,7 +13,7 @@ const MicrosoftSignInButton = () => {