{ "info": { "author": "Miguel Araujo", "author_email": "miguel.araujo.perez@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# requests-oauth2\n\n[![PyPI](https://img.shields.io/pypi/v/requests-oauth2.svg)](https://pypi.python.org/pypi/requests-oauth2)\n\nOAuth v2.0 support for\n[kennethreitz](https://github.com/kennethreitz)'s well-known\n[Requests](https://github.com/kennethreitz/requests) library.\n\nThis library wants to provide the simplest and easiest way to do\nOAuth2 in Python. OAuth2 is much easier to do than old OAuth1.0, and\nlikewise this library is simple, free of cruft, and practical in\neveryday use. If you are looking for a way of doing OAuth 1.0, see\n[requests-oauth](https://github.com/maraujop/requests-oauth).\n\nAuthors: see [AUTHORS](/AUTHORS).\n\nLicense: BSD\n\nExamples: with [Flask](/examples/web_flask.py).\n\n## OAuth2 web app flow - the theory\n\nSkip this if you know how OAuth2 works.\n\n1. Your web app (*Foo*) allows users to log in with their *Qux*\n account. *Qux* here is a service provider; they gave you a **client\n ID** and a **secret key**, which *Foo* stores somewhere on the\n backend. *Qux* and *Foo* pre-agree on some **redirect URI**.\n2. User visits *Foo*'s login screen, e.g.\n `https://www.foo.example/login`\n3. *Foo* redirects users to *Qux*'s **Authorization URL**, e.g.\n `https://api.qux.example/oauth/authorize`\n4. User is presented with *Qux*'s **consent screen**, where they\n review the **scope** of requested permissions, and either allow or\n deny access.\n5. Once access is granted, *Qux* redirects back to *Foo* via the\n **redirect URI** that they both agreed upon beforehand, supplying\n the **code**.\n6. *Foo* exchanges the **code** for an **access token**. The access\n token can be used by *Foo* to make API calls to *Qux* on user's\n behalf.\n\n## Usage example\n\nLook into the [examples directory](/examples) for fully integrated,\nworking examples.\n\nSome providers are included out of the box, but adding more is quite\neasy. In this example, we'll get started with Google.\n\nYou will find **Client ID** & **secret** (point 1 above) in your\n[Google API console](https://console.cloud.google.com/apis/credentials).\n\nYou must choose the **redirect URI**, which must be handled by your\nweb app.\n\n```python\nfrom requests_oauth2.services import GoogleClient\ngoogle_auth = GoogleClient(\n client_id=\"your-google-client-id\",\n client_secret=\"super-secret\",\n redirect_uri=\"http://localhost:5000/google/oauth2callback\",\n)\n```\n\nWhen the user visits the login page (point 2), we'll build an\n**authorization URL** (point 3) that will direct the user to Google's\n**consent screen**, asking to grant the specified **scopes** (point\n4):\n\n```python\nauthorization_url = google_auth.authorize_url(\n scope=[\"email\"],\n response_type=\"code\",\n)\n```\n\nOnce the user clicks \"allow\", Google will redirect them to the\n**redirect URI** (point 5), which will include the **code** as one of\nthe query string parameters:\n\n http://localhost:5000/google/oauth2callback?code=...\n\nThe code will be used to request an **access token** (point 6),\nnecessary for all following requests to the API:\n\n```python\ncode = get_request_parameter(\"code\") # this depends on your web framework!\ndata = google_auth.get_token(\n code=code,\n grant_type=\"authorization_code\",\n)\n```\n\nYou can store it somewhere for later use, e.g. in the session, or in\nthe database:\n\n```python\nsession[\"access_token\"] = data[\"access_token\"]\n```\n\nThe exact method for supplying the **access token** varies from one\nprovider to another. One popular method (supported by Google) is via\nthe Bearer header. There's a helper shortcut for this:\n\n```python\nfrom requests_oauth2 import OAuth2BearerToken\n\nwith requests.Session() as s:\n s.auth = OAuth2BearerToken(access_token)\n r = s.get(\"https://www.googleapis.com/plus/v1/people/me\")\n r.raise_for_status()\n data = r.json()\n```\n\nOther providers, such as Facebook, allow the access token to be passed\nas a request parameter (in the query string). You would so something\nlike this:\n\n```python\nfrom requests_oauth2 import OAuth2BearerToken\n\nwith requests.Session() as s:\n s.params = {\"access_token\": response[\"access_token\"]}\n r = s.get(\"https://graph.facebook.com/me\")\n r.raise_for_status()\n data = r.json()\n```\n\n## Interesting readings\n\n* Using OAuth 2.0 to Access Google APIs:\n \n\n* Using OAuth 2.0 for Web Server Applications Google APIs:\n \n\n* OAuth 2.0 in Facebook:\n \n\n* Github OAuth 2.0 usage:\n \n\n* You can use postbin for testing webhooks: ", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/maraujop/requests-oauth2", "keywords": "requests,python-requests,OAuth,OAuth2", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "requests-oauth2", "package_url": "https://pypi.org/project/requests-oauth2/", "platform": "", "project_url": "https://pypi.org/project/requests-oauth2/", "project_urls": { "Homepage": "http://github.com/maraujop/requests-oauth2" }, "release_url": "https://pypi.org/project/requests-oauth2/0.3.0/", "requires_dist": null, "requires_python": "", "summary": "OAuth2 support to Python-Requests HTTP library.", "version": "0.3.0" }, "last_serial": 3641649, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "ec300234c8eeffedaf974bb981bd1bef", "sha256": "ebfd9052fa992496c8a2c1d158cb49e3513c17a911d7a0a5219580ffa40d0c5c" }, "downloads": -1, "filename": "requests-oauth2-0.1.0.tar.gz", "has_sig": false, "md5_digest": "ec300234c8eeffedaf974bb981bd1bef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3731, "upload_time": "2012-03-12T12:45:20", "url": "https://files.pythonhosted.org/packages/47/24/02979be629a9697052fc89f3b8ff7671479415c5ae92867ceada2c2b6a84/requests-oauth2-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "597c91ed715c65cf9a87b2fa556de8d5", "sha256": "ced031204b48d00fe971bf0a2beb8a6d7639e289719f6a49cc9a036d42bc4067" }, "downloads": -1, "filename": "requests-oauth2-0.1.1.tar.gz", "has_sig": false, "md5_digest": "597c91ed715c65cf9a87b2fa556de8d5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3819, "upload_time": "2012-04-22T21:06:21", "url": "https://files.pythonhosted.org/packages/50/39/acbb3c3e5785ceec2515e8ad972657989e3006d6239af9b65d17b05120bd/requests-oauth2-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "d2218f2f085a52f831bf4a2f49924431", "sha256": "91320e959d948cb99f53d3bfd833c99aa51bb4dbdd31f016d800f9b9066c528c" }, "downloads": -1, "filename": "requests-oauth2-0.2.0.tar.gz", "has_sig": false, "md5_digest": "d2218f2f085a52f831bf4a2f49924431", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3872, "upload_time": "2012-06-13T16:34:20", "url": "https://files.pythonhosted.org/packages/4d/69/6f12422b47bd8962b50e5ad0110d76fc28090608fde2e0753f5d071f33eb/requests-oauth2-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "04257277b39aec5384fc98cea9464331", "sha256": "e99bff042b5f87da83fcb2f8f6b8b82e562319ac36cda3fd0ca5f19fe9717762" }, "downloads": -1, "filename": "requests-oauth2-0.3.0.tar.gz", "has_sig": false, "md5_digest": "04257277b39aec5384fc98cea9464331", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5272, "upload_time": "2018-03-05T20:23:43", "url": "https://files.pythonhosted.org/packages/52/dc/01c3c75e6e7341a2c7a971d111d7105df230ddb74b5d4e10a3dabb61750c/requests-oauth2-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "04257277b39aec5384fc98cea9464331", "sha256": "e99bff042b5f87da83fcb2f8f6b8b82e562319ac36cda3fd0ca5f19fe9717762" }, "downloads": -1, "filename": "requests-oauth2-0.3.0.tar.gz", "has_sig": false, "md5_digest": "04257277b39aec5384fc98cea9464331", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5272, "upload_time": "2018-03-05T20:23:43", "url": "https://files.pythonhosted.org/packages/52/dc/01c3c75e6e7341a2c7a971d111d7105df230ddb74b5d4e10a3dabb61750c/requests-oauth2-0.3.0.tar.gz" } ] }