denoland / deno_kv_oauth

High-level OAuth 2.0 powered by Deno KV.
https://jsr.io/@deno/kv-oauth
MIT License
245 stars 25 forks source link

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

Closed kevingorski closed 8 months ago

kevingorski commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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!