[Fixed]-Django Page not found (404) while using Oauth library (log in with Linkedin)

1πŸ‘

βœ…

From the FAQ:

When I attempt to login I run into a 404 on /accounts/profile/

When you end up here you have successfully logged in. However, you
will need to implement a view for this URL yourself, as whatever is to
be displayed here is project specific. You can also decide to redirect
elsewhere:

https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url

πŸ‘€DanielB

0πŸ‘

LinkedIn authorization needs a redirect_url declared in your My Apps tabs of LinkedIn. When you create your authorization url with all the parameters that you need to specify LinkedIn redirects back you to this callback url with an authorization_code and state.

For example let us assume your parameters for the GET request on the linkedin authorization url is https://www.linkedin.com/uas/oauth2/authorization

import urllib

parameters = {
    'response_type' : 'code',
    'client_id' : '<Your Client Id>',
    'redirect_uri' : 'http://127.0.0.1:8000/accounts/profile/'
    'state' : 'Some String',
    'scope' : r_emailaddress
}

encoded_parameters = urllib.urlencode(parameters)

url = 'https://www.linkedin.com/uas/oauth2/authorization' + '?' + encoded_parameters

After the authentication with linkedin page you will be redirected back to the url http://127.0.0.1:8000/accounts/profile/. So just make sure that this url has been declared in your django app.

πŸ‘€Arpit Goyal

Leave a comment