Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linkedin API - Bad Redirect, invalid redirect URI

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)
like image 465
dasvootz Avatar asked Mar 06 '18 20:03

dasvootz


People also ask

What does invalid redirect URI mean?

While working on a web based client, you have to ensure that the redirect URI passed while authentication, is the same as the one given during registration. If the redirect uri is not the one given during registration, an invalid redirect uri error will be thrown.

Is redirect and callback URL same?

The callback URLs, also known as redirect URIs, tell the server where to send the user with the proper tokens after authentication. For purposes within Skuid, you'll want the end user sent back to the Skuid site/org accessing the data.


2 Answers

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/.

like image 104
andreyrd Avatar answered Sep 29 '22 01:09

andreyrd


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".

like image 32
Adam Trachtenberg Avatar answered Sep 29 '22 02:09

Adam Trachtenberg