Linkedin API - Bad Redirect, invalid redirect URI
Asked Answered
F

2

8

I am using this code with my client ID and client secret:

https://github.com/DEKHTIARJonathan/python3-linkedin/blob/master/examples/oauth2_authentication.py

However, when getting the url back in the command line and putting it into the browser I am getting "invalid redirect_uri. This value must match a URL registered with the API Key."

I've registered the following with redirect urls in an attempt to get it working:

http://localhost:8080/code
https://localhost:8080/code/
http://localhost:8080/code/signin-linkedin
https://localhost:8080/code/signin-linkedin
https%3A//locahost%3A8080/code/

The signin-linkedin piece came from here:

linkedin : Invalid redirect_uri. This value must match a URL registered with the API Key

However, adding that last 'sigin-linkedin' portion didn't alleviate the issue.

This is the URL that I am getting back, # in place of my client_id:

https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=##########&scope=r_basicprofile%20r_emailaddress%20rw_company_admin%20w_share&state=04377850f3154ee3f808f762244697b6&redirect_uri=https%3A//locahost%3A8080/code/

Thanks in advance.

Edit:

I've tried adding some additional urls based on other posts:

https://appname.auth0.com/login/callback

https://appname.auth0.com

Here is my code:

if __name__ == '__main__':

    CLIENT_ID = #######
    CLIENT_SECRET = ##########
    RETURN_URL = 'http://localhost:8080/code/'

    authentication = LinkedInAuthentication(
                    CLIENT_ID,
                    CLIENT_SECRET,
                    RETURN_URL,
                    permissions=['r_basicprofile',
                                 'r_emailaddress',
                                 'rw_company_admin',
                                 'w_share']
                )

    print(authentication.authorization_url)
    application = LinkedInApplication(authentication)
Flame answered 6/3, 2018 at 20:36 Comment(0)
C
3

It looks like your callback URL configuration has a mistake, a missing "l".

If you look closely at the redirect_uri parameter, its value is https%3A//locahost%3A8080/code/ which unescaped is https://locahost:8080/code/.

I assume you mean the value to be configured as https://localhost:8080/code/.

Cephalo answered 8/3, 2018 at 21:9 Comment(4)
Hmm, tbh not sure why the l was missing when I ran it before, might have been when I was trying other stuff out. I put in my code up top in the edits. I'm now getting this as a redirect url but same error (no l missing): linkedin.com/uas/oauth2/…Flame
Has anyone solved this? I am getting the exact same problemLavolta
To be honest, i haven't revisited this issue in over a year so I'm not sure if any solutions have been found.Flame
Are there any solutions to this? Thanks!Telescopic
A
1

Your URL encoding of the redirect_uri looks incorrect.

For me, http://localhost:8080/code/ turns into http%3A%2F%2Flocalhost%3A8080%2Fcode%2F.

You are sending "/" when it should be "%2F".

Avowal answered 14/5, 2019 at 6:58 Comment(1)
If your redirect URL is what you have in the example, then you should be sending it as I posted it in my original answer. Then there should not get an "invalid redirect URL" error. (That error means that what you're sending isn't a URL listed in your application settings.) You are likely getting this because it's improperly escaped, not because it needs to be one of those auth0 URLs from another post.Avowal

© 2022 - 2024 — McMap. All rights reserved.