如何解决将 NextAuth 与 oauth_get_access_token_error 和 oauth_callback_error 一起使用时登录回调错误
我正在尝试将自定义 oauth 提供程序添加到我的 next.js 应用程序。我在 [...nextauth].js
中添加自定义提供程序:
export default NextAuth({
// Configure one or more authentication providers
providers: [
{
id: "moneybutton",name: "Money Button",type: "oauth",version: "2.0",scope: "auth.user_identity:read users.profiles:read users.profiles.email:read users.balance:read",params: {
grant_type: "authorization_code"
},accessTokenUrl: "https://www.moneybutton.com/oauth/v1/token",requestTokenUrl: "https://www.moneybutton.com/oauth/v1/token",authorizationUrl: "https://www.moneybutton.com/oauth/v1/authorize?response_type=code",profileUrl: "https://www.moneybutton.com/api/v1/auth/user_identity",profile(profile) {
return {
id: profile.data.attributes.id,name: profile.data.attributes.name,};
},clientId: 'my_oauth_identifier',clientSecret: 'my_client_secret'
}
// ...add more providers here
],debug: true
});
OAuth 流程似乎工作正常,因为我看到我的个人资料 ID 在响应中返回,但它在 http://localhost:3000/api/auth/signin?error=Callback
我将调试设置为 true,但出现以下错误:
[next-auth][error][oauth_get_access_token_error]
https://next-auth.js.org/errors#oauth_get_access_token_error {
statusCode: 400,data: '{"errors":[{"id":"6da534f0-a512-11eb-92e8-891975d02f44","status":400,"title":"Bad Request","detail":"Invalid client: client is invalid"}],"jsonapi":{"version":"1.0"}}'
} undefined undefined
[next-auth][error][oauth_get_access_token_error]
https://next-auth.js.org/errors#oauth_get_access_token_error {
statusCode: 400,"jsonapi":{"version":"1.0"}}'
} moneybutton 9f3970b8ae39f9d46f9fae56f6fb6135ecb7e87b
[next-auth][error][oauth_callback_error]
https://next-auth.js.org/errors#oauth_callback_error {
statusCode: 400,"jsonapi":{"version":"1.0"}}'
它说客户端无效,但我确定 oauth 标识符和密码是正确的,并且重定向 URL 设置为 http://localhost:3000/api/auth/callback/moneybutton
。
如果有帮助的话,对个人资料的回复看起来像这样:
{
"data": {
"id": "75101","type": "user_identities","attributes": {
"id": "75101","name": "John Doe"
}
},"jsonapi": {
"version": "1.0"
}
}
文档链接:
- https://next-auth.js.org/configuration/providers
- https://docs.moneybutton.com/docs/api/v1/api-v1-user-identity
我不知道这是错误还是我的方法有误,希望得到任何帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。