Package: dj-sso-server2
dj-sso-serveris a Django application that provides Single Sign-on feature for your project.Thedj-sso-serverapplication works as aSSO provider, you can usedj-sso-client(https://github.com/tofu0913/dj-sso-client) as theSSO clientin other projects need SSO.InstallationInstall by commandpip installdj-sso-serverThe dependent packagedj-api-auth(https://github.com/feifangit/dj-api-auth) will be installed automatically.How it worksBased on thedj-api-authmodule, we can create an API key with SSO related APIs initially included. All the API communications betweendj-sso-serveranddj-sso-clientare protected bydj-api-authThe API key will also be bind with ahostwhich is used to limit the origin of SSO requests.SSO work flow withdj-sso-clientFirstly,dj-sso-clientapplies arequest keyvia APIreqeusttoken/ondj-sso-serverTherequest keyindj-sso-serverside will be kept in cache for 5 minutes, so the whole SSO login process should be done in 5 minutes.With therequest key,dj-sso-clientredirects user to SSO login page on SSO provider, and getauth tokenif login success.dj-sso-serverwillverify the request originverifyrequest keyvalidity (expired?)save user information in cachedj-sso-clientverifies theauth tokenwithdj-sso-servervia APIauthtoken/, and get aSSOUserobject.dj-sso-serverdelete therequest keyfrom cache once theauthtoken/is called.If there’s an already logged-in account ondj-sso-server(say, the project where SSO provider is placed also provides other features, and there’s a valid cookies in browser side and valid session on server side), user can select to continue with that logged account.SSO login throughdj-sso-serverwith not affect the login status ondj-sso-server.AttentionSincerequest keysare stored in cache waiting for verification or expiration. If you have multiple application process running in your deployment (gunicorn etc.), please use proper cache system that can be shared between processes.Memcached and Redis are both great for caching, be aware, theLocal-memory caching(django.core.cache.backends.locmem.LocMemCache) is a toy for local debugging.Adddj-sso-serverto projectAdddjapiauthanddjssoservertoINSTALLED_APPSinsttings.pyAssign an URL to the module# add auth for a browser-oriented viewurl(r'^sso/',include("djssoserver.urls"))#...SettingsSSO_SERVER_USER_TO_JSON_FUNCoptional, a path to function receives an user object and return a json string.the defaultSSO_SERVER_USER_TO_JSON_FUNCfunction isdjssoserver.utility.default_user_to_jsondefdefault_user_to_json(user):returnjson.dumps(model_to_dict(user,exclude=["password","user_permissions"]),cls=DjangoJSONEncoder)Scan APIIn order to discover and manage APIs, afterdj-sso-serveris added in an accessibleurls.py, run commandpython manage.py reloadentrypointsto collect APIs to database.Create API key for SSOFrom your admin site, create an API key atSinglesign-on/SSOcredential. All SSO related APIs will assigned to this API Key automatically.After the API key for SSO is ready, you can assign more APIs for this API key atAPI Auth/Credentialfrom admin siteCustomize SSO login pageYou can add styles to your own SSO login page. simply createdjsso/ssologin.htmlunder thetemplatesfolder. Revamp it by imitating theoriginal pageSSOUser objectdj-sso-clientgets aSSOUserobject whatever the User model is used in SSO provider project.See detail in README file ofdj-sso-client(https://github.com/tofu0913/dj-sso-client)DEMOWe have a SSO provider application running on Heroku (https://dj-sso-sample.herokuapp.com/).Source code: underexamplefolderTo try the demo out, check out the README file ofdj-sso-client(https://github.com/tofu0913/dj-sso-client)