gpt4 book ai didi

oauth - 为什么 next auth 说需要 client_id,即使在不和谐的提供者中,显然有一个 client_id

转载 作者:行者123 更新时间:2023-12-05 05:46:32 27 4
gpt4 key购买 nike

当我尝试使用 next auth 创建一个 discord oauth 客户端并单击登录时,出现此错误:

https://next-auth.js.org/errors#get_authorization_url_error client_id is required {
message: 'client_id is required',
stack: 'TypeError: client_id is required\n' +
' at new BaseClient (/Users/muyuan/Documents/minibot/node_modules/openid-client/lib/client.js:178:13)\n' +
' at new Client (/Users/muyuan/Documents/minibot/node_modules/openid-client/lib/client.js:1823:7)\n' +
' at openidClient (/Users/muyuan/Documents/minibot/node_modules/next-auth/core/lib/oauth/client.js:28:18)\n' +
' at getAuthorizationUrl (/Users/muyuan/Documents/minibot/node_modules/next-auth/core/lib/oauth/authorization-url.js:67:51)\n' +
' at Object.signin (/Users/muyuan/Documents/minibot/node_modules/next-auth/core/routes/signin.js:37:60)\n' +
' at NextAuthHandler (/Users/muyuan/Documents/minibot/node_modules/next-auth/core/index.js:191:39)\n' +
' at processTicksAndRejections (internal/process/task_queues.js:95:5)\n' +
' at async NextAuthNextHandler (/Users/muyuan/Documents/minibot/node_modules/next-auth/next/index.js:21:19)\n' +
' at async /Users/muyuan/Documents/minibot/node_modules/next-auth/next/index.js:57:32\n' +
' at async Object.apiResolver (/Users/muyuan/Documents/minibot/node_modules/next/dist/server/api-utils.js:101:9)',
name: 'TypeError'
}
[next-auth][error][SIGNIN_OAUTH_ERROR]
https://next-auth.js.org/errors#signin_oauth_error client_id is required {
error: {
message: 'client_id is required',
stack: 'TypeError: client_id is required\n' +
' at new BaseClient (/Users/muyuan/Documents/minibot/node_modules/openid-client/lib/client.js:178:13)\n' +
' at new Client (/Users/muyuan/Documents/minibot/node_modules/openid-client/lib/client.js:1823:7)\n' +
' at openidClient (/Users/muyuan/Documents/minibot/node_modules/next-auth/core/lib/oauth/client.js:28:18)\n' +
' at getAuthorizationUrl (/Users/muyuan/Documents/minibot/node_modules/next-auth/core/lib/oauth/authorization-url.js:67:51)\n' +
' at Object.signin (/Users/muyuan/Documents/minibot/node_modules/next-auth/core/routes/signin.js:37:60)\n' +
' at NextAuthHandler (/Users/muyuan/Documents/minibot/node_modules/next-auth/core/index.js:191:39)\n' +
' at processTicksAndRejections (internal/process/task_queues.js:95:5)\n' +
' at async NextAuthNextHandler (/Users/muyuan/Documents/minibot/node_modules/next-auth/next/index.js:21:19)\n' +
' at async /Users/muyuan/Documents/minibot/node_modules/next-auth/next/index.js:57:32\n' +
' at async Object.apiResolver (/Users/muyuan/Documents/minibot/node_modules/next/dist/server/api-utils.js:101:9)',
name: 'TypeError'
},
provider: {
id: 'discord',
name: 'Discord',
type: 'oauth',
authorization: {
url: 'https://discord.com/api/oauth2/authorize',
params: [Object]
},
token: { url: 'https://discord.com/api/oauth2/token', params: {} },
userinfo: { url: 'https://discord.com/api/users/@me', params: {} },
profile: [Function: profile],
idToken: false,
checks: [ 'state' ],
client_id: my client id(not actually 'my client id'),
client_secret: my client secret(not actually 'my client secret'),
signinUrl: 'http://localhost:3000/api/auth/signin/discord',
callbackUrl: 'http://localhost:3000/api/auth/callback/discord'
},
message: 'client_id is required'
}

这就是我定义不和谐提供者的方式:

import NextAuth from "next-auth"
import DiscordProvider from "next-auth/providers/discord"

export default NextAuth({
// Configure one or more authentication providers
providers: [
DiscordProvider({
client_id: process.env.DISCORD_CLIENT_ID,
client_secret: process.env.DISCORD_CLIENT_SECRET
})
],
secret: "hello1234567890",
debug: true
})

显然有一个client_id。为什么它仍然给我那个错误?同样在我的网站上,当我点击“使用不和谐登录”时,它显示“尝试使用其他帐户登录”。

最佳答案

我不是专家,但您是否尝试过更改配置对象属性名称?
我相信它们应该是 camelCase 而不是 snake_case

✅ “clientId”
❌ “client_id”

DiscordProvider({
clientId: process.env.DISCORD_CLIENT_ID,
clientSecret: process.env.DISCORD_CLIENT_SECRET
})

关于oauth - 为什么 next auth 说需要 client_id,即使在不和谐的提供者中,显然有一个 client_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71159469/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com