{"library":"repoze.who","title":"repoze.who (Identification & Authentication for WSGI)","description":"repoze.who is an identification and authentication framework for WSGI applications. It provides middleware to manage user identification, authentication, and authorization. The current stable version is 3.1.0, and it is actively maintained by the Pylons Project, though releases are infrequent.","language":"python","status":"maintenance","last_verified":"Thu Apr 16","install":{"commands":["pip install repoze.who"],"cli":null},"imports":["from repoze.who.config import make_who_with_config","from repoze.who.config import make_who_with_config # Indirectly used","from repoze.who.config import add_new_r_w_to_environ"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom webob.dec import wsgify\nfrom webob import Response\nfrom repoze.who.config import make_who_with_config, add_new_r_w_to_environ\nfrom repoze.who.plugins.basicauth import BasicAuthPlugin # Example plugin\n\n# Dummy WSGI application\n@wsgify\ndef my_app(request):\n    identity = request.environ.get('repoze.who.identity')\n    if identity:\n        username = identity.get('repoze.who.userid')\n        return Response(f'Hello, {username}! You are authenticated.')\n    else:\n        return Response('Please authenticate.', status=401)\n\n# Configure repoze.who\n# For real applications, use proper credential storage\nusers_db = {'admin': 'secret', 'user': 'password'}\n\ndef my_authenticator(environ, identity):\n    if 'login' in identity and 'password' in identity:\n        login = identity['login']\n        password = identity['password']\n        if users_db.get(login) == password:\n            identity['repoze.who.userid'] = login # Store userid\n            return login\n    return None\n\n# Example challenge (basic auth)\nbasic_auth_plugin = BasicAuthPlugin('My Realm')\n\n# Who config dictionary (simplified)\nwho_config = {\n    'identifiers': [('basic_auth_identifier', basic_auth_plugin)],\n    'authenticators': [('my_auth', my_authenticator)],\n    'challengers': [('basic_auth_challenger', basic_auth_plugin)],\n    'log_stream': None,\n    'log_level': 10 # DEBUG\n}\n\n# Create WhoMiddleware\nwho_middleware_app = make_who_with_config(my_app, who_config)\n\n# Wrap the app to ensure 'repoze.who' object is in environ\n@wsgify\ndef wrapped_app(request):\n    add_new_r_w_to_environ(request.environ, who_config)\n    return who_middleware_app(request)\n\n# To run this with a WSGI server (e.g., waitress):\n# pip install webob waitress\n# from waitress import serve\n# serve(wrapped_app, host='0.0.0.0', port=8000)\n# (Uncomment above lines to run)\n","lang":"python","description":"This quickstart demonstrates setting up `repoze.who` with a basic authenticator and `BasicAuthPlugin` for identification and challenging. It shows how to use `make_who_with_config` to create the middleware and `add_new_r_w_to_environ` to populate the WSGI environment, then access the identity from `request.environ`. To run this example, you will also need to install `webob` and a WSGI server like `waitress`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}