WSGI Basic Auth¶
Really simple wsgi middleware to provide basic http auth. It is intented to work with environment variables. This makes it simple to use in a docker context.
Using this module is really simple. In Django for example edit the wsgi.py file and add the following to the end of the file.
from wsgi_basic_auth import BasicAuth
application = BasicAuth(application)
Now run docker with the env variable WSGI_AUTH_CREDENTIALS=foo:bar and you have to authenticate with username foo and password bar. Multiple credentials are separated with a | (pipe) character.
To exclude specific paths for healthchecks (e.g. the Amazon ELB healthchecks) specify the environment variable WSGI_AUTH_EXCLUDE_PATHS=/api/healthchecks. Here multiple paths can be separated with the ; char.
To include only specific paths specify the environment variable WSGI_AUTH_EXCLUDE_PATHS. Here multiple paths can be separated with the ; char.
You can use both include and exclude paths together for example: WSGI_AUTH_PATHS=/foo WSGI_AUTH_EXCLUDE_PATHS=/foo/bar This will force Basic Auth on all paths under /foo except /foo/bar
Options¶
-
class
wsgi_basic_auth.
BasicAuth
(app, realm='Protected', users=None, exclude_paths=None, include_paths=None, env_prefix='')¶ WSGI Middleware to add Basic Authentication to an existing wsgi app.
Parameters: - app – the wsgi application
- realm – the basic auth realm. Default = ‘protected’
- users – dictionary with username -> password mapping. When not
supplied the values from the environment variable
WSGI_AUTH_CREDENTIALS
. If no users are defined then the middleware is disabled. - exclude_paths – list of path prefixes to exclude from auth. When not
supplied the values from the
WSGI_AUTH_EXCLUDE_PATHS
environment variable are used (splitted by;
) - include_paths – list of path prefixes to include in auth. When not
supplied the values from the
WSGI_AUTH_PATHS
environment variable are used (splitted by;
) - env_prefix – prefix for the environment variables above, default
''