Package: django-vouch-proxy-auth
django-vouch-proxy-authDjango Middleware enabling the use of theVouch Proxycookie for single sign-on.This package subclasses Django'sRemoteUserMiddlewareandRemoteUserBackend.How it WorksThe middleware checks for the presence of the Vouch Proxy cookie.If the cookie exists, it attempts to load a previous validation from Django cache.If the validation result is not in the Cache, send the contents of theVouchCookiecookie to the Vouch Proxy/validateendpoint.If the validation is successful, decode and decompress the cookie and extract the username from the JWT payload.Save the username in cache with a short expiration and use the SHA256 sum of theVouchCookieas the key. (i.e.VouchCookie_+sha256sum(VouchCookie))Installation and Usagepip install django-vouch-proxy-author adddjango-vouch-proxy-authto your requirements file.To enable the middleware, adddjango_vouch_proxy_auth.middleware.VouchProxyMiddlewareafter Django'sAuthenticationMiddleware.MIDDLEWARE=['django.contrib.auth.middleware.AuthenticationMiddleware',...'django_vouch_proxy_auth.middleware.VouchProxyMiddleware']This middleware is also dependent on theVouchProxyUserBackendAuthentication Backend. Add anywhere in yourAUTHENTICATION_BACKENDS.AUTHENTICATION_BACKENDS=('django_vouch_proxy_auth.backends.VouchProxyUserBackend')Finally, you MUST tell the middleware where the/validateendpoint is. Add theVOUCH_PROXY_VALIDATE_ENDPOINTto your Djangosettings.pyfile.VOUCH_PROXY_VALIDATE_ENDPOINT='https://login.avacado.lol/validate'SettingsVOUCH_PROXY_VALIDATE_ENDPOINTLocation of the Vouch Proxy validation endpoint. You MUST provide this value, or the Middleware will raise anImproperlyConfiguredexception.VOUCH_PROXY_VERIFY_SSLDefault:TrueSet this to False to ignore verification of the Vouch Proxy SSL certificate.VOUCH_PROXY_COOKIE_NAMEDefault:VouchCookieChange this setting if you are using a custom Vouch Proxy cookie name.VOUCH_PROXY_CACHE_TIMEOUTDefault:300(seconds)This middleware will cache the username if a successful response from the/validatequery is returned. To reduce the load on Vouch Proxy, the middleware will only validate the cookie every 300 seconds (5 minutes) by default.Set this value to a positive integer if you want to change the cache timeout.Set this to0if you want Django to query the Vouch Proxy/validateendpoint on every request.VOUCH_PROXY_CACHE_PREFIXDefault: defaults to the configured value forVOUCH_PROXY_COOKIE_NAMEplus underscore (i.e.VouchCookie_)Set this value if you want to change the prefix for the CacheKey.VOUCH_PROXY_CACHE_BACKENDDefault:defaultSet this value if you want to store cached results in a different cache.VOUCH_PROXY_DISABLED_PATHSDefault:[]Set this value (as an array) to full paths that you want to disable the middleware.For example, if you have other middleware that causes conflict:VOUCH_PROXY_DISABLED_PATHS=['/oidc/authenticate/','/oidc/callback/']VOUCH_PROXY_CREATE_UNKNOWN_USERDefault:TrueSet this to False if you do not want the middleware to automatically create a user entry on first login. You must use theVOUCH_PROXY_FORCE_LOGOUT_IF_NO_COOKIEDefault:FalseSet this toTrueif you want Django to logout the user if the Vouch Cookie is not present.