Package: dj-sso-server
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/feifangit/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_MODEL_TO_DICT_CLSoptional, a path to JSON encoder classthe default encoder processesdatetime,date,timeanddecimal.Decimal# DjangoJSONEncoder from Django 1.7 source codeclassDjangoJSONEncoder(json.JSONEncoder):"""
    JSONEncoder subclass that knows how to encode date/time and decimal types.
    """defdefault(self,o):# See "Date Time String Format" in the ECMA-262 specification.ifisinstance(o,datetime.datetime):r=o.isoformat()ifo.microsecond:r=r[:23]+r[26:]ifr.endswith('+00:00'):r=r[:-6]+'Z'returnrelifisinstance(o,datetime.date):returno.isoformat()elifisinstance(o,datetime.time):ifis_aware(o):raiseValueError("JSON can't represent timezone-aware times.")r=o.isoformat()ifo.microsecond:r=r[:12]returnrelifisinstance(o,decimal.Decimal):returnstr(o)else:returnsuper(DjangoJSONEncoder,self).default(o)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/feifangit/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/feifangit/dj-sso-client)