After disabling the default configuration of repoze.who
by removing all the base_config.sa_auth...
and base_config.auth_backend
from config/app_.cfg.py
it should be possible to configure repoze.who as middleware in config/middleware.py
.
so i created a file config/auth.py
like this:
from logging import getLogger
from repoze.who.middleware import PluggableAuthenticationMiddleware
from repoze.who.classifiers import default_challenge_decider, default_request_classifier
from repoze.who.plugins.basicauth import BasicAuthPlugin
from repoze.who.plugins.htpasswd import HTPasswdPlugin, plain_check
def add_auth(app):
htpasswd = HTPasswdPlugin('/.../htpasswd', plain_check)
authenticators = [('htpasswd', htpasswd)]
base_auth = BasicAuthPlugin('Inventory DB')
challengers = [('base_auth', base_auth)]
identifiers = [('base_auth', base_auth)]
mdproviders = []
log_stream = getLogger('auth')
app_with_mw = PluggableAuthenticationMiddleware(
app,
identifiers,
authenticators,
challengers,
mdproviders,
default_request_classifier,
default_challenge_decider,
log_stream,
)
return app_with_mw
where plain_text passwords are used just for testing. Then, in config/middleware.py
this function is imported and applied to the app
as the last step in the make_app
function.
from invdb.config.app_cfg import base_config
from invdb.config.environment import load_environment
from auth import add_auth
__all__ = ['make_app']
make_base_app = base_config.setup_tg_wsgi_app(load_environment)
def make_app(global_conf, full_stack=True, **app_conf):
app = make_base_app(global_conf, full_stack=True, **app_conf)
app = add_auth(app)
return app
The problem is now, that the authentication does not really work. Controllers that do not require any authentication don't challenge. A controller with allow_only = tg.predicate.not_anonymous
will challenge a http-authentication. But even if plain_check returns True
the login is instantly forgotten and the challenge is displayed again. tg.request.identity
stays None
.
What am I doing wrong?