You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Next-Auth集成LinkedIn时遇OAUTH_CALLBACK_ERROR错误求助

Next-Auth LinkedIn登录:解决OAUTH_CALLBACK_ERROR(jwks_uri must be configured on the issuer)

你的问题源于两处关键配置错误,导致Next-Auth无法正确验证LinkedIn返回的ID Token,进而无法获取用户数据:

  1. JWKS端点参数名错误
    Next-Auth的OAuth Provider配置中,指定JWKS端点的标准参数是jwksUri,而非你使用的jwks_endpoint。错误的参数名会被框架忽略,导致无法找到验证Token所需的密钥。

  2. Issuer地址不正确
    LinkedIn OpenID Connect服务的正确issuer是https://www.linkedin.com/oauth/openid,而非根域名https://www.linkedin.com。使用根域名作为issuer会导致Next-Auth无法匹配到正确的OIDC配置。

修改后的代码示例

LinkedInProvider({
  clientId: process.env.LINKEDIN_CLIENT_ID as string,
  clientSecret: process.env.LINKEDIN_CLIENT_SECRET as string,
  authorization: {
    params: { scope: 'openid profile email' },
  },
  issuer: 'https://www.linkedin.com/oauth/openid',
  jwksUri: 'https://www.linkedin.com/oauth/openid/jwks',
  profile(profile, tokens) {
    const defaultImage = 'https://cdn-icons-png.flaticon.com/512/174/174857.png';
    return {
      id: profile.sub,
      name: profile.name,
      email: profile.email,
      image: profile.picture ?? defaultImage,
    };
  },
}),

额外验证步骤

  • 确认LinkedIn开发者应用已启用OpenID Connect功能(在应用的"Auth"设置页)。
  • 检查回调URL是否配置为https://你的域名/api/auth/callback/linkedin(本地开发可使用http://localhost:3000/api/auth/callback/linkedin)。
  • 确保openid profile email权限已在LinkedIn应用中获批。

内容的提问来源于stack exchange,提问作者Samitha Wijesekara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 00:22:14