Top Related Projects
Social auth made simple
Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication. 🔁 Mirror of https://codeberg.org/allauth/django-allauth/
OAuth2 goodies for the Djangonauts!
Quick Overview
Social-app-django is a Django app that provides social authentication integration for Django projects. It's part of the python-social-auth ecosystem and allows developers to easily add social login functionality to their Django applications using various social platforms like Facebook, Google, Twitter, and more.
Pros
- Easy integration with Django projects
- Supports a wide range of social authentication providers
- Customizable and extensible
- Active community and regular updates
Cons
- Can be complex to set up for beginners
- Documentation could be more comprehensive
- Requires additional configuration for each social provider
- May introduce security risks if not properly implemented
Code Examples
- Basic configuration in settings.py:
INSTALLED_APPS = [
# ...
'social_django',
]
AUTHENTICATION_BACKENDS = [
'social_core.backends.google.GoogleOAuth2',
'social_core.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
]
- URL configuration in urls.py:
from django.urls import path, include
urlpatterns = [
# ...
path('social-auth/', include('social_django.urls', namespace='social')),
]
- Template example for login buttons:
<a href="{% url 'social:begin' 'google-oauth2' %}">Login with Google</a>
<a href="{% url 'social:begin' 'facebook' %}">Login with Facebook</a>
- Accessing user data in a view:
from django.contrib.auth.decorators import login_required
@login_required
def profile(request):
user = request.user
social_account = user.social_auth.get(provider='google-oauth2')
extra_data = social_account.extra_data
return render(request, 'profile.html', {'extra_data': extra_data})
Getting Started
-
Install the package:
pip install social-auth-app-django
-
Add 'social_django' to INSTALLED_APPS in settings.py
-
Add social auth backends to AUTHENTICATION_BACKENDS in settings.py
-
Include social_django URLs in your project's urls.py
-
Configure social auth settings for your chosen providers (e.g., SOCIAL_AUTH_GOOGLE_OAUTH2_KEY, SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET)
-
Run migrations:
python manage.py migrate
-
Add social login buttons to your templates and start using social authentication in your Django project.
Competitor Comparisons
Social auth made simple
Pros of python-social-auth
- More comprehensive and feature-rich, supporting a wider range of authentication backends
- Offers greater flexibility and customization options
- Actively maintained with regular updates and improvements
Cons of python-social-auth
- Steeper learning curve due to its more complex architecture
- May be overkill for simpler projects that only require basic social authentication
- Requires more configuration and setup compared to social-app-django
Code Comparison
python-social-auth:
from social_core.backends.oauth import BaseOAuth2
class CustomOAuth2(BaseOAuth2):
name = 'custom'
AUTHORIZATION_URL = 'https://example.com/oauth/authorize'
ACCESS_TOKEN_URL = 'https://example.com/oauth/token'
social-app-django:
from social_core.backends.oauth import BaseOAuth2
class CustomOAuth2(BaseOAuth2):
name = 'custom'
AUTHORIZATION_URL = 'https://example.com/oauth/authorize'
ACCESS_TOKEN_URL = 'https://example.com/oauth/token'
The code structure for defining custom OAuth2 backends is similar in both libraries, as social-app-django is built on top of python-social-auth. The main differences lie in the setup, configuration, and integration with Django projects.
Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication. 🔁 Mirror of https://codeberg.org/allauth/django-allauth/
Pros of django-allauth
- More comprehensive authentication solution, including features like email verification and password reset
- Supports a wider range of authentication providers out-of-the-box
- More active development and community support
Cons of django-allauth
- Steeper learning curve due to more complex configuration
- Potentially more overhead for simpler authentication needs
- Less flexibility in customizing the authentication flow
Code Comparison
django-allauth configuration:
INSTALLED_APPS = [
...
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.github',
]
AUTHENTICATION_BACKENDS = [
'allauth.account.auth_backends.AuthenticationBackend',
]
social-app-django configuration:
INSTALLED_APPS = [
...
'social_django',
]
AUTHENTICATION_BACKENDS = [
'social_core.backends.github.GithubOAuth2',
]
Both libraries offer Django integration for social authentication, but django-allauth provides a more comprehensive solution with additional features. social-app-django is simpler to set up and may be preferable for projects with basic authentication needs. The code comparison shows that django-allauth requires more configuration but offers more built-in functionality.
OAuth2 goodies for the Djangonauts!
Pros of django-oauth-toolkit
- Focused specifically on OAuth2 implementation, providing a more comprehensive and standards-compliant solution
- Better suited for building OAuth2 providers and handling complex authorization scenarios
- More active development and maintenance, with regular updates and improvements
Cons of django-oauth-toolkit
- Steeper learning curve due to its more specialized nature
- Less out-of-the-box support for various social authentication providers
- May require additional configuration and setup for simple authentication use cases
Code Comparison
django-oauth-toolkit:
from oauth2_provider.views.generic import ProtectedResourceView
class ApiEndpoint(ProtectedResourceView):
def get(self, request, *args, **kwargs):
return HttpResponse('Hello, OAuth2!')
social-app-django:
from social_django.utils import psa
@psa()
def auth_by_token(request, backend):
user = request.backend.do_auth(request.GET.get('access_token'))
if user:
login(request, user)
return HttpResponse("Logged in as: {0}".format(user.username))
The code snippets demonstrate the different approaches: django-oauth-toolkit focuses on creating protected views using OAuth2, while social-app-django simplifies social authentication with decorators and backend-specific methods.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Python Social Auth - Django
Python Social Auth is an easy to setup social authentication/registration mechanism with support for several frameworks and auth providers.
Description
This is the Django component of the python-social-auth ecosystem, it implements the needed functionality to integrate social-auth-core in a Django based project.
Django version
This project will focus on the currently supported Django releases as stated on the Django Project Supported Versions table.
Backward compatibility with unsupported versions won't be enforced.
Documentation
Project documentation is available at https://python-social-auth.readthedocs.io/.
Setup
$ pip install social-auth-app-django
Contributing
Contributions are welcome!
Only the core and Django modules are currently in development. All others are in maintenance only mode, and maintainers are especially welcome there.
See the CONTRIBUTING.md document for details.
Versioning
This project follows Semantic Versioning 2.0.0.
License
This project follows the BSD license. See the LICENSE for details.
Donations
This project welcomes donations to make the development sustainable, you can fund Python Social Auth on following platforms:
Top Related Projects
Social auth made simple
Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication. 🔁 Mirror of https://codeberg.org/allauth/django-allauth/
OAuth2 goodies for the Djangonauts!
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot