Django is a high-level Python web framework that promotes swift development and clean, pragmatic design. Its goal is to provide the infrastructure required for web development, allowing you to focus on writing your app. It’s free and open source, supported by a large community of developers.
Django follows a “batteries included” philosophy. It provides many features, like authentication and messaging, out of the box, without requiring you to install separate libraries. Django also provides scalability, allowing developers to build high-performing, elegant web applications that can scale to handle large amounts of traffic. When it comes to security, Django helps developers avoid common security weaknesses, such as cross-site scripting, SQL injection, and clickjacking.
When it comes to single sign on (SSO), Django does not provide a built-in module, but there are several open source libraries you can use to extend its functionality and provide SSO to your users. We’ll focus on one of these, called django-simple-sso.
Here are a few reasons you should consider implementing SSO in your Django application:
django-simple-sso is an open-source library designed to integrate Single Sign-On (SSO) functionality into Django applications. It serves as a bridge between a Django server, which acts as the SSO provider, and one or more Django clients, which utilize the SSO service for authentication. The primary components of django-simple-sso are the Server, which holds user information and handles authentication, and the Client, a Django website that facilitates login via SSO using the Server.
django-simple-sso manages user authentication centrally at the Server level, thereby simplifying the login process across multiple Client applications. The library uses a combination of a public ‘Key’ for identifying a Client and a private ‘Secret’ for secure communication between the Server and each Client. These mechanisms ensure that user credentials and authentication processes are handled securely and efficiently.
Django-simple-sso ensures secure communication by using HMAC-SHA256 for signing all requests, ensuring the integrity and authenticity of the data exchanged between the Server and Clients. Each request is accompanied by a signature, created using the Secret key, which the Server verifies to authenticate the request.
Here is how django-simple-sso’s authentication workflow works:
This process ensures that the user’s login credentials remain secure and are not directly handled by the Client applications.
Here is how to set up the server side. The server will handle authentication for all the client apps:
pip install django-simple-sso
python manage.py migrate
DJANGO_SETTINGS_MODULE
settings.configure()
from simple_sso.sso_server.models import Token, Consumer Consumer.objects.create(public_key='client_app_public_key', private_key='client_app_private_key', name='app_name')
simple_sso.sso_server
NSTALLED_APPS
from simple_sso.sso_server.server import Server my_server = Server() urlpatterns += [ url(r'^server/', include(my_server.get_urls())), ]
Here is how to set up the client side for one of your applications:
SSO_PRIVATE_KEY = 'app_private_key' SSO_PUBLIC_KEY = 'app-public-key' SSO_SERVER = 'server-url'
from simple_sso.sso_client.client import Client my_client_1 = Client(settings.SSO_SERVER, settings.SSO_PUBLIC_KEY, settings.SSO_PRIVATE_KEY) url(r’^client/’, include(my_client_1.get_urls())),
Try to create at least two applications using the process above, setting a different hostname for each application via the /etc/hosts file.
To test your Django SSO authentication process works, do the following:
Django-simple-sso is designed to handle single sign-on within Django applications efficiently. However, its scalability can be a challenge in large-scale deployments. As the number of client applications increases, the server may experience higher loads during peak authentication periods. Additionally, the server-based architecture means that all authentication requests must pass through a central server, which could become a bottleneck if not adequately scaled.
While django-simple-sso provides a robust mechanism for secure communication using HMAC-SHA256, its security is highly dependent on the proper management of keys and the overall configuration. If the secret keys are compromised, malicious entities could potentially impersonate legitimate clients or intercept authentication data. Moreover, since django-simple-sso centralizes authentication, the security of the entire system is reliant on the security of the server. Any vulnerabilities in the server’s setup or in the way it handles requests can expose all connected clients to risks.
Django-simple-sso is specifically tailored for Django applications, which means integration with non-Django systems can be complex and sometimes unfeasible without additional customization. Organizations using a diverse set of technologies may find it challenging to implement django-simple-sso across all platforms. This limitation could require additional development work to create compatible interfaces or might necessitate the use of additional bridging technologies to ensure seamless SSO functionality across different systems.
While django-simple-sso covers the fundamental aspects of SSO, its feature set might be limited compared to more comprehensive SSO solutions like OAuth2 or OpenID Connect. For example, it lacks built-in support for multi-factor authentication (MFA), detailed logging for security audits, or advanced user session management features such as session revocation or timeout controls. These features are often crucial for enterprises requiring rigorous security standards and granular control over user sessions and authentication mechanisms.
Frontegg is a user management solution with full support for Django. Once you integrate Frontegg’s self-served user management solution, your customers can configure their SSO completely on their own with just a few lines of code. The single sign-on can be integrated with IDPs with commonly-used protocols like OIDC and SAML. Yes, you can implement social login SSOs as well. The front end has been taken care of as well.
You can leverage all of Frontegg’s SSO components and personalize your SaaS offering with a login box builder. This embeddable box reduces implementation times as no in-house development is required. Users can authenticate smoothly and gain quick access to the app, without waiting for product updates and fixes. A true end-to-end SSO solution for SaaS apps and services.
Learn more about Frontegg for authentication