Can not verify JWT token of Azure AD with openid scope in java

I am developing a Backend code for a BallSportsGear to log in to our application in Login with Azure Ad User. I have to be able to make a JWT Verify. I read too many posts. I’m trying to use the AUTH0 library. I have tried a lot, but still "com.auth Where do I make mistakes?

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

const handler = NextAuth({
  providers: [
    CredentialsProvider({
      name: "Credentials",
      credentials: {
        username: { label: "Username", type: "text" },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials, req) {
        const { username, password } = credentials as { username: string; password: string };
        const res = await fetch("http://localhost:3000/api/auth/login", {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({ username, password }),
        });
        const user = await res.json();
        if (res.ok) {
          return user;
        } else {
          return null;
        }
      },
    }),
  ],
  session: {
    strategy: "jwt"
  },
});

export { handler as GET, handler as POST };

layout.tsx

'use client'

import './globals.css'
import { SessionProvider } from "next-auth/react"


export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>
        <SessionProvider>
          {children}
        </SessionProvider>
      </body>
    </html>
  )
}

First of all you have to Import Statement In the first code snippet, you import CredentialsProvider from next-auth/providers/credentials. However, for Azure AD authentication, you should use the AzureAdProvider instead. Make sure you have installed the next-auth and @next-auth/azure-ad packages. Then rovider Configuration: Update your NextAuth configuration to include the AzureAdProvider with the required configuration options, such as clientId, clientSecret, tenantId, etc. These values can be obtained from your Azure AD application registration.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.