By Moin ul Haq – Software Engineer | Web Developer | Django Enthusiast
Integrating LinkedIn OAuth in Django can be tricky, especially when you want smooth authentication and proper user data handling. In this guide, I’ll walk you through using Django Allauth with OpenID Connect for LinkedIn login, tackling real-world issues I faced while building client-facing web apps.

Why LinkedIn OAuth?
LinkedIn login is perfect when you want:
- Users to sign up quickly using their LinkedIn profiles.
- Secure authentication without managing passwords.
- Access to professional user data like email, name, and profile URL.
Most tutorials cover Google or Facebook, but LinkedIn’s OpenID Connect implementation often confuses developers. Let’s solve it step by step.
Step 1: Install Dependencies
Start with Django and Allauth:
pip install django
pip install django-allauth[openidconnect]
Make sure your Django project is set up with INSTALLED_APPS updated:
INSTALLED_APPS = [
...
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.openid_connect',
]
SITE_ID = 1
Step 2: Configure LinkedIn as OpenID Connect Provider
- Go to LinkedIn Developer Portaland create a new app.
- Add OAuth 2.0 redirect URLs, e.g.,
http://localhost:8000/accounts/openid/login/callback/ - Note your Client ID and Client Secret.
Step 3: Add Provider in Django Admin
Django Allauth allows dynamic configuration:
- Login to Django Admin → Social Applications → Add LinkedIn.
- Select Site →
example.com(or localhost for testing). - Enter Client ID and Secret Key.
- Use OpenID Connect as Provider type.
Step 4: Update URLs
Add Allauth URLs to your urls.py:
from django.urls import path, include
urlpatterns = [
path('accounts/', include('allauth.urls')),
...
]
Step 5: Frontend Integration
Add a simple login button in your template:
<a href="{% provider_login_url 'openid_connect' %}?process=login">
Login with LinkedIn
</a>
⚠️ Tip: Always use {% provider_login_url %} instead of hardcoding URLs to avoid callback issues.
Step 6: Handling Common Problems
1. “Invalid redirect_uri”
- Make sure the redirect URI in LinkedIn app matches exactly with the one Django Allauth uses.
2. User Email Not Returned
- LinkedIn requires r_emailaddress permission. Ensure your Allauth provider scope includes:
SOCIALACCOUNT_PROVIDERS = {
'openid_connect': {
'SCOPE': ['openid', 'email', 'profile']
}
}
3. Tokens Not Saved
- Allauth stores tokens in SocialToken. Always check the SocialApp and SocialAccount entries in Django Admin.
Step 7: Verify Everything Works
Run server:
python manage.py runserverClick Login with LinkedIn → authorize → redirected to dashboard.
Check
request.user→ should have LinkedIn email, name, and token.
Personal Branding Angle
While implementing this, I realized professional networking login flows not only save development time but also improve user trust. As a developer, mastering OAuth integrations with Django is a strong portfolio highlight, showing clients that you can handle enterprise-grade authentication.
💡 Pro Tip: Post your projects integrating OAuth on GitHub with proper README and a live demo. Recruiters and clients love this.
Conclusion
Using Django Allauth + OpenID Connect makes LinkedIn OAuth integration straightforward if you handle:
- Provider scopes correctly.
- Redirect URIs precisely.
- Tokens and user data securely.
This setup not only improves user experience but also demonstrates your capability to solve complex authentication challenges professionally.
🔗 About Me
I’m Moin ul Haq, a software engineer building scalable Django applications. I write about real-world solutions, web development challenges, and software best practices. Check out my projects on GitHub.
Top comments (0)