Python WSGI Repoze.who basic Auth not asking for user and password

125 views Asked by At

i'm tryng to use repoze.who for authentincation into wsgi apache Python 3.8 apt-get -y install python3 libexpat1 apache2 apache2-utils ssl-cert libapache2-mod-wsgi-py3

I've configured apache: nano /etc/apache2/conf-available/mod-wsgi.conf

WSGIPassAuthorization On
WSGIScriptAlias /test_wsgi /var/www/scripts/test.py

then

a2enconf mod-wsgi a2enmod wsgi

and in test.py

def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
yield 'Hello World\n'

if i launch http://myip/test_wsgi

i got Hello World

now if i try to copy the sample auth with repoze.who i try to put that code into /var/www/scripts/test.py:

    from repoze.who.middleware import PluggableAuthenticationMiddleware
    from repoze.who.interfaces import IIdentifier
    from repoze.who.interfaces import IChallenger
    from repoze.who.plugins.basicauth import BasicAuthPlugin
    from repoze.who.plugins.auth_tkt import AuthTktCookiePlugin
    from repoze.who.plugins.redirector import RedirectorPlugin
    from repoze.who.plugins.htpasswd import HTPasswdPlugin,plain_check
    from io import StringIO
    import logging, sys
    
    
    def app(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/html')])
        return [b"good user"]
    
    
    io = StringIO()
    salt = 'aa'
    for name, password in [ ('admin', 'admin'), ('chris', 'chris') ]:
        io.write('%s:%s\n' % (name, password))
    io.seek(0)
    def cleartext_check(password, hashed):
        return password == hashed
    htpasswd = HTPasswdPlugin(io, cleartext_check)
    basicauth = BasicAuthPlugin('repoze.who')
    identifiers = [('basicauth', basicauth)]
    authenticators = [('htpasswd', htpasswd)]
    challengers = [('basicauth', basicauth)]
    mdproviders = []
    
    from repoze.who.classifiers import default_request_classifier
    from repoze.who.classifiers import default_challenge_decider
    log_stream = None
    import os
    log_stream = sys.stdout
    
    middleware = PluggableAuthenticationMiddleware(
        app,
        identifiers,
        authenticators,
        challengers,
        mdproviders,
        default_request_classifier,
        default_challenge_decider,
        log_stream = log_stream,
        log_level = logging.DEBUG
        )
    
    
    application = middleware

Now if i launch my script from browser (http://myip/test_wsgi) i got "good user" and never got auth form basic for insert my credential.

Any help ?

0

There are 0 answers