Django linkedIn Social authentication

123 views Asked by At

Someone please help, Please read it fully(I have tried a lot of methods lately from different sources)

its been more than 30 days I'm trying to get 'Sign in with LinkedIn' button, but no good.. ill just show you my code:

My LinkedIn ID and key(have tried without REDIRECT_URL line as well)

#MY LINKEDIN APP
SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = 'ID'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'KEY'
REDIRECT_URI = 'http://localhost:8000/oauth/complete/linkedin-oauth2/'`


URLS
`urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('home.urls')),
    path('oauth/', include('social_django.urls', namespace='social')),
]`

LinkedIn Button
`<!--LINKEDIN BUTTON-->
        <li class="linkedin">
    <a href="{% url "social:begin" backend="linkedin-oauth2" %}">
    Sign in with Linkedin
    </a>
    </li>`

Nothing's wrong with the coding..

`INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'home',
    'social_django',

]



LOGIN_REDIRECT_URL = 'dashboard'
LOGOUT_REDIRECT_URL = 'login'
LOGIN_URL = 'login'
LOGOUT_URL = 'logout'

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'social_core.backends.github.GithubOAuth2',
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.linkedin.LinkedinOAuth2',


)

LinkedIn app is okay, Redicrect URI mathces as well`

`Error after Clicking Sign in with LinkedIn
Bummer, something went wrong.
In five seconds, you will be redirected to: localhost



Django error
AuthFailed at /oauth/complete/linkedin-oauth2/
Authentication failed: Scope &quot;r_liteprofile&quot; is not authorized for your application

I understand it needs the "r_liteprofile" scope, But I cant see that anywhere, neither inside OAuth 2.0 tools

solution to this r_liteprofile scope error!

LinkedIn Authentication Error

Afterwards Django error

1

There are 1 answers

0
vdavez On

I had this exact problem earlier today! The solution I used was to swap out the linkedin_oauth2 provider with the LinkedIn OpenID Connect provider from django-allauth.

I added this to settings.py (along with allauth.socialaccount.providers.openid_connect in the installed apps):

SOCIALACCOUNT_PROVIDERS = {
    "openid_connect": {
        "APPS": [
            {
                "provider_id": "linkedin-server",
                "name": "LinkedIn OIDC",
                "client_id": os.environ.get("LINKEDIN_OIDC_CLIENT_ID"),
                "secret": os.environ.get("LINKEDIN_OIDC_CLIENT_SECRET"),
                "settings": {
                    "server_url": "https://www.linkedin.com/oauth",
                },
            }
        ]
    },
}

Then, make sure you use http://localhost:8000/accounts/oidc/linkedin-server/login/callback/ for the redirect_uri.

Hope that helps!