Search code examples
oauth-2.0linkedin-api

LinkedIn - Getting Access Token Error invalid_redirect_uri


has anyone succeeded in connecting to Linkedin API here? I followed the instructions on the docs but failed to retrieve the Authorization Code. Here's the result of my POST request to get the access_token

enter image description here

{
    "error": "invalid_redirect_uri",
    "error_description": "Unable to retrieve access token: appid/redirect uri/code verifier does not match authorization code. Or authorization code expired. Or external member binding exists"
}

I'm using the https//airbyte.io as a redirect_uri My GET get request to obtain the authorization token is the following:

https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=78oy2gu644mxz2&redirect_uri=https%3A%2F%2Fairbyte.io&scope=r_ads,r_ads_reporting,r_organization_social

I followed a couple advices in the different thread in SO

  • double checked my client_id and client_secret
  • encoded the URI in GET request
  • added scope parameters to the redirect_url at the POST request
  • Tested the request with the code within 20 seconds window.

Solution

  • Couple of things:

    1. Ensure your redirect URI is also defined within your app's configuration as an allowed redirect URI. See https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin%2Fmarketing%2Fcontext&view=li-lms-2022-11&tabs=HTTPS1#step-1-configure-your-application. The documentation specifies a certain URL to use when testing with Postman.
    2. In your authorization call, your scopes are comma-delimited. They should be space-delimited and URL-encoded. See https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin%2Fmarketing%2Fcontext&view=li-lms-2022-11&tabs=HTTPS1#step-2-request-an-authorization-code.