LinkedIn 的 Next-Auth 会抛出错误 [next-auth][error][OAUTH_CALLBACK_ERROR] jwks_uri 必须在颁发者上配置 jwks_uri 必须配置

问题描述 投票:0回答:1

我尝试将 Next-Auth 与 LinkedIn 结合使用,但收到此错误。

[next-auth][error][OAUTH_CALLBACK_ERROR]  https://next-auth.js.org/errors#oauth_callback_error jwks_uri must be configured on the issuer { error: TypeError: jwks_uri must be configured on the issuer at assertIssuerConfiguration

登录过程非常顺利。但登录 LinkedIn 后,它不会向我返回用户数据。而且用户也不会显示为登录状态。Pararrely 我正在使用 Google 登录,它运行得很好。 LinkedIn 出现的问题。有人可以解决这个错误,这将非常有帮助。

我尝试了以下代码。

    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',
      jwks_endpoint: '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,
        };
      },
    }),
next.js linkedin-api next.js13 next-auth
1个回答
0
投票

试试这个方法

  LinkedInProvider({
      clientId: process.env.LINKEDIN_CLIENT_ID,
      clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
      client: { token_endpoint_auth_method: "client_secret_post" },
      scope: "r_liteprofile r_emailaddress",
      issuer: "https://www.linkedin.com",
      userinfo: {
        url: "https://api.linkedin.com/v2/userinfo",
      },
      tokenUri: "https://www.linkedin.com/oauth/v2/accessToken",
      wellKnown:
        "https://www.linkedin.com/oauth/.well-known/openid-configuration",
      authorization: {
        url: "https://www.linkedin.com/oauth/v2/authorization",
        params: {
          scope: "profile email openid",
          prompt: "consent",
          access_type: "offline",
          response_type: "code",
        },
      },
     
      token: {
        url: "https://www.linkedin.com/oauth/v2/accessToken",
      },
      jwks_endpoint: "https://www.linkedin.com/oauth/openid/jwks",
      async profile(profile) {
        return {
          id: profile.sub,
          name: profile.name,
          firstname: profile.given_name,
          lastname: profile.family_name,
          email: profile.email,
        };
      },
    }),
© www.soinside.com 2019 - 2024. All rights reserved.