Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"client_id" is missing when using a custom OAuth config for LinkedIn #282

Closed
kevingorski opened this issue Dec 20, 2023 · 5 comments · May be fixed by #287
Closed

"client_id" is missing when using a custom OAuth config for LinkedIn #282

kevingorski opened this issue Dec 20, 2023 · 5 comments · May be fixed by #287

Comments

@kevingorski
Copy link

I'm not sure if this is properly for this repo or oauth2_client, but please let me know if that's the case.

I created an app in the LinkedIn developer portal, used the ID/secret locally and was able to go through the auth flow on LI (which leads me to believe the client id is set correctly on my end), but when handling the access token response I get the error in the title (and at the end of this issue).

LinkedIn's OAuth docs say to include the client ID and secret again in the call to get the access token – I'm not sure if that's non-standard?

Here is my client config:

export const linkedInOAuth2Client: OAuth2ClientConfig = {
  authorizationEndpointUri: "https://www.linkedin.com/oauth/v2/authorization",
  clientId: getRequiredEnv("LINKED_IN_CLIENT_ID"),
  clientSecret: getRequiredEnv("LINKED_IN_CLIENT_SECRET"),
  redirectUri: `${SITE_BASE_URL}/linkedInCallback`,
  tokenUri: "https://www.linkedin.com/oauth/v2/accessToken",
  defaults: {
    scope: [
      "email",
      "openid",
      "profile",
    ],
  },
};

Relevant part of the stack trace:

Error: A required parameter "client_id" is missing
    at AuthorizationCodeGrant.getTokenResponseError (https://deno.land/x/oauth2_client@v1.0.2/src/grant_base.ts:156:14)
    at eventLoopTick (ext:core/01_core.js:181:11)
    at async AuthorizationCodeGrant.parseTokenResponse (https://deno.land/x/oauth2_client@v1.0.2/src/grant_base.ts:72:13)
    at async handleCallback (https://deno.land/x/deno_kv_oauth@v0.10.0/lib/handle_callback.ts:69:18)
@iuioiua
Copy link
Contributor

iuioiua commented Dec 21, 2023

Hi Kevin, you're configuration looks correct. I believe that this is a non-standard requirement. I've drafted a quick fix. Please let me know if it works.

  1. Import using https://raw.githubusercontent.com/denoland/deno_kv_oauth/handle-callback-request-options/mod.ts
  2. Add a 3rd argument to handleCallback() with the following structure:
    {
      requestOptions: {
        urlParams: {
          client_id: getRequiredEnv("LINKED_IN_CLIENT_ID"),
          client_secret: getRequiredEnv("LINKED_IN_CLIENT_SECRET"),
          redirect_uri: `${SITE_BASE_URL}/linkedInCallback`,
        },
      },
    }

@kevingorski
Copy link
Author

Thanks for the quick response!

I tried it with both requestOptions: { urlParams: { ... } } and with requestOptions: { body: { ... } } as the third param to handleCallback and I get the same error message with the updated path for handleCallback:

Error: A required parameter "client_id" is missing
    at AuthorizationCodeGrant.getTokenResponseError (https://deno.land/x/oauth2_client@v1.0.2/src/grant_base.ts:156:14)
    at eventLoopTick (ext:core/01_core.js:181:11)
    at async AuthorizationCodeGrant.parseTokenResponse (https://deno.land/x/oauth2_client@v1.0.2/src/grant_base.ts:72:13)
    at async handleCallback (https://raw.githubusercontent.com/denoland/deno_kv_oauth/handle-callback-request-options/lib/handle_callback.ts:71:18)

If it helps, here's the code I'm working with.

@iuioiua
Copy link
Contributor

iuioiua commented Dec 22, 2023

Good thinking trying requestOptions: { body: { ... } }. But I thought that would've worked. The best course of action is to add a pre-built OAuth config for LinkedIn as part of this library (we'd need it sooner or later anyway). Then, troubleshooting can be boiled down to only a few moving parts. I'm happy to do this if no one grabs it up.

@kevingorski
Copy link
Author

As I noted in the related PR, I'm able to set up the custom config so I no longer run into the "client_id is missing" error even without the handleCallback change, (now I've got a different and opaque error from LinkedIn that I can't yet troubleshoot) so feel free to close this whenever.

@iuioiua
Copy link
Contributor

iuioiua commented Dec 28, 2023

I'll close this issue for now but will still pursue #287, as it'll hopefully prevent issues relating to LinkedIn from popping up in the future. Thank you, Kevin!

@iuioiua iuioiua closed this as completed Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants