Single sign on is a way for users to issue a security token for the first time login, login into multiple applications using one set of credentials i.e security token.
Adding sso to an application will make things easier for users, because they dont need to remember login credentials for multiple applications. User just need to enter their login credentials for first time instead of re-entering their credentials for every application login.
In this post, we'll see how to add single sign on to multiple django applications using django-simple-sso.
Using django-simple-sso, we should have single server, multiple clients.
How Django SSO works for multiple applications?
User --> application -- > SSO Server --> application
Server Side:
pip install django-simple-sso
2. Run the following command to store each client or application details, user tokens.
python manage.py migrate
3. Create application or client details(public key, priavte key) in the server side in the django shell.
from simple_sso.sso_server.models import Token, Consumer
Consumer.objects.create(public_key='your_application_public_key', private_key='your_application_private_key', name='your_application_name')
4. Add 'simple_sso.sso_server' to INSTALLED_APPS
INSTALLED_APPS = INSTALLED_APPS + (
'simple_sso.sso_server'
)
5. Intialize the server and add the following url patterns to urls.py file:
from simple_sso.sso_server.server import Server
test_server = Server()
urlpatterns += [
url(r'^server/', include(test_server.get_urls())),
]
Client Side:
pip install django-simple-sso
2. Add Public key, private key, server url to application settings
SSO_PRIVATE_KEY = 'Your Private Key'
SSO_PUBLIC_KEY = 'Your Public Key'
SSO_SERVER = 'SSO SERVER URL'
3. Initialize the client and add the following client urls to application urls:
from simple_sso.sso_client.client import Client
test_client = Client(settings.SSO_SERVER, settings.SSO_PUBLIC_KEY, settings.SSO_PRIVATE_KEY)
url(r'^client/', include(test_client.get_urls())),
Create 2 client apps with the above settings. Add different hostname to your appplication using /etc/hosts file.
Visits your application http://test.yourapp.com:8000/client/, it'll ask for user credentials if not logged in already. After successful login, visits other application http://test.testyourapp.com:8001/client/, user'll be logged in already.