我试图在https://next-auth.js.org/providers/azure-ad-b2c和https://next-auth.js.org/adapters/prisma文章之后用next-auth实现azure-ad-b2c登录。但是现在我遇到了错误。知道是什么问题吗?
错误
https://next-auth.js.org/errors#signin_oauth_error expected 200 OK, got: 404 Not Found {
error: {
message: 'expected 200 OK, got: 404 Not Found',
stack: 'OPError: expected 200 OK, got: 404 Not Found\n' +
' at processResponse (/home/leokorr/Projects/app-tests/microsoft-test/node_modules/openid-client/lib/helpers/process_response.js:41:11)\n' +
' at Function.discover (/home/leokorr/Projects/app-tests/microsoft-test/node_modules/openid-client/lib/issuer.js:152:20)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:96:5)\n' +
' at async openidClient (/home/leokorr/Projects/app-tests/microsoft-test/node_modules/next-auth/core/lib/oauth/client.js:16:14)\n' +
' at async getAuthorizationUrl (/home/leokorr/Projects/app-tests/microsoft-test/node_modules/next-auth/core/lib/oauth/authorization-url.js:65:18)\n' +
' at async Object.signin (/home/leokorr/Projects/app-tests/microsoft-test/node_modules/next-auth/core/routes/signin.js:37:24)\n' +
' at async NextAuthHandler (/home/leokorr/Projects/app-tests/microsoft-test/node_modules/next-auth/core/index.js:238:26)\n' +
' at async NextAuthNextHandler (/home/leokorr/Projects/app-tests/microsoft-test/node_modules/next-auth/next/index.js:23:19)\n' +
' at async /home/leokorr/Projects/app-tests/microsoft-test/node_modules/next-auth/next/index.js:59:32\n' +
' at async Object.apiResolver (/home/leokorr/Projects/app-tests/microsoft-test/node_modules/next/dist/server/api-utils/node.js:366:9)',
name: 'OPError'
},
providerId: 'azure-ad-b2c',
message: 'expected 200 OK, got: 404 Not Found'
}
[...下一个日期. js]
import NextAuth from "next-auth"
import AzureADB2CProvider from "next-auth/providers/azure-ad-b2c"
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
export default NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
AzureADB2CProvider({
tenantId: process.env.AZURE_AD_TENANT_ID,
clientId: process.env.AZURE_AD_CLIENT_ID,
clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
primaryUserFlow: process.env.AZURE_AD_B2C_PRIMARY_USER_FLOW,
authorization: { params: { scope: "offline_access openid" } },
})
],
})
index.js
import { signIn } from 'next-auth/react'
export default function Home() {
const handleLoginb2c = () => signIn('azure-ad-b2c', {
callbackUrl: `http://localhost:3000/loggedin`,
}).catch((error) => console.log(error))
return (
<div>
<button onClick={handleLoginb2c}>b2c Log in</button>
</div>
);
}
2条答案
按热度按时间xlpyo6sf1#
tenantId、clientId、clientSecret应该是不同的envs。租户ID必须是不带.onmicrosoft.com的租户名称。如果不起作用,请检查Azure应用程序重定向URI:x1月1x日x1月1x日
uubf1zoe2#
请确保您使用的是租户名称而不是租户ID,该值的位置可以在下图中找到(红色部分)。它是您在设置租户时选择的任何字母数字值(位于. www.example.com之前onmicrosoft.com)。
我以前有ID,当我切换到这个值时,它就像一个魅力。希望这有帮助!