{ "info": { "author": "Alexander Polishchuk", "author_email": "apolishchuk52@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: AsyncIO", "Intended Audience :: Developers", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "# aiohttp-tokenauth\n\nAiohttp simple token auth middleware that can check any token that assign to user or group of users in database or some another place.\n\n## Installation\n```bash\npip install aiohttp_tokenauth\n```\n\n## Documentation\n\n### Basic usage\nFirst of all, let's create a simple app.\n```python\n# Full text in example/simple_app.py\nfrom aiohttp import web\nfrom aiohttp_tokenauth import token_auth_middleware\n\n\nasync def example_resource(request):\n return web.json_response(request['user'])\n\n\nasync def init():\n\n async def user_loader(token: str):\n \"\"\"Checks that token is valid\n\n It's the callback that will get the token from \"Authorization\" header.\n It can check that token is exist in a database or some another place.\n\n Args:\n token (str): A token from \"Authorization\" http header.\n\n Returns:\n Dict or something else. If the callback returns None then\n the aiohttp.web.HTTPForbidden will be raised.\n \"\"\"\n user = None\n if token == 'fake-token':\n user = {'uuid': 'fake-uuid'}\n return user\n\n app = web.Application(middlewares=[token_auth_middleware(user_loader)])\n app.router.add_get('/', example_resource)\n return app\n\n\nif __name__ == '__main__':\n web.run_app(init())\n```\nThen, run the aiohttp app.\n```bash\n$ python example/simple_app.py\n======== Running on http://0.0.0.0:8080 ========\n(Press CTRL+C to quit)\n```\nNow try to get access to url with token in \"Authorization\" header.\n```bash\n$ curl -H 'Authorization: Bearer fake-token' http://0.0.0.0:8080\n{\"uuid\": \"fake-uuid\"}\n```\nAnd result without token.\n```bash\n$ curl http://0.0.0.0:8080\n401: Missing authorization header\n```\n\n### Ignoring routes and http methods\nYou can ignore specific routes, app the paths to \"exclude_routes\".\n```python\napp = web.Application(middlewares=[\n token_auth_middleware(\n user_loader=user_loader,\n # You can use regular expressions here\n exclude_routes=('/exclude', r'/exclude/\\w+/info'),\n exclude_methods=('POST',),\n ),\n])\n```\n\n### Change auth scheme\nFor changing the scheme (prefix in \"Authorization\" header) use `auth_scheme` argument.\n```python\napp = web.Application(middlewares=[\n token_auth_middleware(\n user_loader=user_loader,\n auth_scheme='Token',\n ),\n])\n```\nNow such request is valid:\n```bash\n$ curl -H 'Authorization: Token fake-token' http://0.0.0.0:8080\n{\"uuid\": \"fake-uuid\"}\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/madnesspie/aiohttp-tokenauth", "keywords": "", "license": "GNU General Public License v3 or later (GPLv3+)", "maintainer": "", "maintainer_email": "", "name": "aiohttp-tokenauth", "package_url": "https://pypi.org/project/aiohttp-tokenauth/", "platform": "POSIX", "project_url": "https://pypi.org/project/aiohttp-tokenauth/", "project_urls": { "Homepage": "https://github.com/madnesspie/aiohttp-tokenauth" }, "release_url": "https://pypi.org/project/aiohttp-tokenauth/0.0.2/", "requires_dist": null, "requires_python": "", "summary": "Simple way to add token auth level in your aiohttp app", "version": "0.0.2" }, "last_serial": 5819956, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "9381badc328a7ee8845c9dad181fbd2e", "sha256": "c36763199a3f1d8a2592eee944322e554b4714f2a2a46350bf019e3d647e915d" }, "downloads": -1, "filename": "aiohttp-tokenauth-0.0.1.tar.gz", "has_sig": false, "md5_digest": "9381badc328a7ee8845c9dad181fbd2e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2365, "upload_time": "2019-09-11T19:22:21", "url": "https://files.pythonhosted.org/packages/80/09/1cac2645f38ee39c2831dd94c4a2c0d81e1f25ad28c383b2ef8578ce06b4/aiohttp-tokenauth-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "9ab963379a877661ccb81c6dd2052a38", "sha256": "460a9ac6094f41489607a3f25590c0cad83e37f3c503a5c62fae3567188b6068" }, "downloads": -1, "filename": "aiohttp-tokenauth-0.0.2.tar.gz", "has_sig": false, "md5_digest": "9ab963379a877661ccb81c6dd2052a38", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3459, "upload_time": "2019-09-12T11:26:30", "url": "https://files.pythonhosted.org/packages/08/3a/7799199476d9b125e17a8e4451412e901352db0610ea9c6dd4ff64617314/aiohttp-tokenauth-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9ab963379a877661ccb81c6dd2052a38", "sha256": "460a9ac6094f41489607a3f25590c0cad83e37f3c503a5c62fae3567188b6068" }, "downloads": -1, "filename": "aiohttp-tokenauth-0.0.2.tar.gz", "has_sig": false, "md5_digest": "9ab963379a877661ccb81c6dd2052a38", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3459, "upload_time": "2019-09-12T11:26:30", "url": "https://files.pythonhosted.org/packages/08/3a/7799199476d9b125e17a8e4451412e901352db0610ea9c6dd4ff64617314/aiohttp-tokenauth-0.0.2.tar.gz" } ] }