{ "info": { "author": "Matt Rasband", "author_email": "matt.rasband@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython" ], "description": "# aiohttp-oauth2\n\n[![CircleCI](https://circleci.com/gh/mrasband/aiohttp-oauth2.svg?style=svg)](https://circleci.com/gh/mrasband/aiohttp-oauth2)\n\nA provider agnostic oauth2 client library for aiohttp, implemented as a self-composed nested application.\n\nNo opinions about auth mechanisms are enforced on the application, an `on_login` and `on_error` coroutine can, and should, be provided to implement your own login mechanisms (token, session, etc).\n\n## Usage\n\n```bash\n$ pip install -U aiohttp_oauth2\n```\n\n### Simple\n\n```python\nfrom aiohttp import web\n\nfrom aiohttp_oauth2 import oauth2_app\n\n\nasync def app_factory():\n app = web.Application()\n\n app.add_subapp(\n \"/github/\", # any arbitrary prefix\n oauth2_app(\n client_id=123,\n client_secret=456,\n authorize_url=\"https://github.com/login/oauth/authorize\",\n token_url=\"https://github.com/login/oauth/access_token\",\n # add scopes if you want to customize them\n scopes=[\"foo\", \"bar\", \"baz\"],\n # optionally add an on_login coroutine to handle the post-login logic\n # it should expect the request and the oauth2 access code response\n on_login=set_session_and_redirect,\n on_error=show_error_page,\n ),\n )\n\n return app\n```\n\nThe necessary oauth2 routes are added as `/auth` and `/callback`. Now logging in a user is as simple as redirecting them to: `/github/auth`.\n\n### Complex\n\nSince the `oauth2_app` function is simply a factory that generates sub-apps, you can use this to add any number of oauth2 providers to log in against:\n\n```python\nfrom aiohttp import web\nfrom aiohttp_oauth2 import oauth2_app\n\n\nasync def app_factory() -> web.Application:\n app = web.Application()\n\n app.add_subapp(\n \"/github/\",\n oauth2_app(\n ...,\n authorize_url=\"https://github.com/login/oauth/authorize\",\n token_url=\"https://github.com/login/oauth/access_token\",\n )\n )\n app.add_subapp(\n \"/google/\",\n oauth2_app(\n ...,\n authorize_url=\"https://accounts.google.com/o/oauth2/v2/auth\",\n token_url=\"https://www.googleapis.com/oauth2/v4/token\",\n )\n )\n app.add_subapp(\n \"/twitter/\",\n oauth2_app(\n ...,\n authorize_url=\"https://api.twitter.com/oauth/authorize\",\n token_url=\"https://api.twitter.com/oauth2/token\",\n )\n )\n\n ...\n\n return app\n```\n\nYou can now redirect users to `/twitter/auth`, `/google/auth`, and `/github/auth`.\n\nAs a nice shortcut to the boilerplate of the authorize/token URLs, see the [`aiohttp_oauth2/client/contrib.py`](https://github.com/mrasband/aiohttp-oauth2/blob/master/aiohttp_oauth2/client/contrib.py) helpers to avoid needing to set the urls explicity.\n\n```python\nimport os\n\nfrom aiohttp import web\nfrom aiohttp_oauth2.client.contrib import github\n\n\nasync def app_factory() -> web.Application:\n app = web.Application()\n\n app.add_subapp(\n \"/login/github\",\n github(\n os.getenv(\"CLIENT_ID\"),\n os.getenv(\"CLIENT_SECRET\"),\n ),\n )\n\n # and/or `google`, `slack`, `twitter` instead of `github`\n\n return app\n```\n\n### Examples\n\nCheck the \"examples\" directory for working examples:\n\n```\n$ cd examples\n$ pip install -r requirements.txt\n\n# this just makes the library available for import, don't typically do it :D\n$ PYTHONPATH=\"..\" python github.py\n```\n\n\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/mrasband/aiohttp-oauth2", "keywords": "aiohttp,oauth2", "license": "", "maintainer": "", "maintainer_email": "", "name": "aiohttp-oauth2", "package_url": "https://pypi.org/project/aiohttp-oauth2/", "platform": "", "project_url": "https://pypi.org/project/aiohttp-oauth2/", "project_urls": { "Homepage": "https://github.com/mrasband/aiohttp-oauth2" }, "release_url": "https://pypi.org/project/aiohttp-oauth2/0.0.4/", "requires_dist": [ "aiohttp" ], "requires_python": ">=3.7.0", "summary": "Provider agnostic OAuth2 client for aiohttp", "version": "0.0.4" }, "last_serial": 5616601, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "8980699574a63dcd55d197f955442c9b", "sha256": "6d6f89e5f95bafd12605b813a61f8bafba608890288d111586bcfa294f78c53d" }, "downloads": -1, "filename": "aiohttp-oauth2-0.0.2.tar.gz", "has_sig": false, "md5_digest": "8980699574a63dcd55d197f955442c9b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 3365, "upload_time": "2019-05-16T21:12:18", "url": "https://files.pythonhosted.org/packages/01/71/1de4b3ec594c1fa345573c6a84bb1d91da1894e5acb8682afe132c4b6183/aiohttp-oauth2-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "54a8a4e95d65eba578b1e1fcc3df6f53", "sha256": "97fae02ec7a513697ed0c84a94ca5eecfce27078957e4f8f2ff79f7d605e7734" }, "downloads": -1, "filename": "aiohttp_oauth2-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "54a8a4e95d65eba578b1e1fcc3df6f53", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7.0", "size": 5661, "upload_time": "2019-06-09T14:03:01", "url": "https://files.pythonhosted.org/packages/88/12/4b206772a1c4a117c16321fcd494a5f8a7af57d7ac4a133bf0a872a16c91/aiohttp_oauth2-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3144db96c1600ac95a8f8f1136f14072", "sha256": "bcf78dddfd233a26bc1b2b0f9685226343087e7f45ad37dace33d2133c1e4b8c" }, "downloads": -1, "filename": "aiohttp-oauth2-0.0.3.tar.gz", "has_sig": false, "md5_digest": "3144db96c1600ac95a8f8f1136f14072", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 3794, "upload_time": "2019-06-09T14:03:02", "url": "https://files.pythonhosted.org/packages/50/25/ac3374c4ec1224a8fca609d4c141ed8b64edc8124703b641a2c1c5b8ea9f/aiohttp-oauth2-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "601fee6a210863f012ba47f83807aaa7", "sha256": "479d681188e275a6d98f21f78db495451bf829294cfcb9804ca5ffd5bdfad41d" }, "downloads": -1, "filename": "aiohttp_oauth2-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "601fee6a210863f012ba47f83807aaa7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7.0", "size": 6290, "upload_time": "2019-08-01T04:21:30", "url": "https://files.pythonhosted.org/packages/fa/2f/7f5fe38773e1e18bc891b61d656353ca59e11a038d207a2f1244274ae4d6/aiohttp_oauth2-0.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5ded87a2864c17241d885f60cc95c93a", "sha256": "8332bdcf6dcf4926a37b4ba14562c1b132d78e16f44615ba43b8ca2d2b9dcb35" }, "downloads": -1, "filename": "aiohttp-oauth2-0.0.4.tar.gz", "has_sig": false, "md5_digest": "5ded87a2864c17241d885f60cc95c93a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 4447, "upload_time": "2019-08-01T04:21:33", "url": "https://files.pythonhosted.org/packages/df/54/2abde7d24fa6270b48d58ad420c2e6bc662fc2e3adaab7127f03fafa1771/aiohttp-oauth2-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "601fee6a210863f012ba47f83807aaa7", "sha256": "479d681188e275a6d98f21f78db495451bf829294cfcb9804ca5ffd5bdfad41d" }, "downloads": -1, "filename": "aiohttp_oauth2-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "601fee6a210863f012ba47f83807aaa7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7.0", "size": 6290, "upload_time": "2019-08-01T04:21:30", "url": "https://files.pythonhosted.org/packages/fa/2f/7f5fe38773e1e18bc891b61d656353ca59e11a038d207a2f1244274ae4d6/aiohttp_oauth2-0.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5ded87a2864c17241d885f60cc95c93a", "sha256": "8332bdcf6dcf4926a37b4ba14562c1b132d78e16f44615ba43b8ca2d2b9dcb35" }, "downloads": -1, "filename": "aiohttp-oauth2-0.0.4.tar.gz", "has_sig": false, "md5_digest": "5ded87a2864c17241d885f60cc95c93a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 4447, "upload_time": "2019-08-01T04:21:33", "url": "https://files.pythonhosted.org/packages/df/54/2abde7d24fa6270b48d58ad420c2e6bc662fc2e3adaab7127f03fafa1771/aiohttp-oauth2-0.0.4.tar.gz" } ] }