From 2329eebb0f4015052bf4ca809da040119ad06b25 Mon Sep 17 00:00:00 2001 From: L2501 Date: Sun, 26 Nov 2023 12:51:43 +0000 Subject: [PATCH] [script.module.requests_oauthlib] 1.3.1+matrix.1 --- .../{LICENSE => LICENSE.txt} | 0 script.module.requests_oauthlib/README.rst | 58 ------------------ script.module.requests_oauthlib/addon.xml | 38 ++++++------ .../lib/requests_oauthlib/__init__.py | 2 +- .../compliance_fixes/__init__.py | 2 +- .../compliance_fixes/ebay.py | 23 +++++++ .../compliance_fixes/linkedin.py | 21 ------- .../lib/requests_oauthlib/oauth1_session.py | 2 +- .../lib/requests_oauthlib/oauth2_session.py | 6 ++ .../{ => resources}/icon.png | Bin 10 files changed, 50 insertions(+), 102 deletions(-) rename script.module.requests_oauthlib/{LICENSE => LICENSE.txt} (100%) delete mode 100644 script.module.requests_oauthlib/README.rst create mode 100644 script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/ebay.py delete mode 100644 script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/linkedin.py rename script.module.requests_oauthlib/{ => resources}/icon.png (100%) diff --git a/script.module.requests_oauthlib/LICENSE b/script.module.requests_oauthlib/LICENSE.txt similarity index 100% rename from script.module.requests_oauthlib/LICENSE rename to script.module.requests_oauthlib/LICENSE.txt diff --git a/script.module.requests_oauthlib/README.rst b/script.module.requests_oauthlib/README.rst deleted file mode 100644 index 5b23615075..0000000000 --- a/script.module.requests_oauthlib/README.rst +++ /dev/null @@ -1,58 +0,0 @@ -Requests-OAuthlib |build-status| |coverage-status| |docs| -========================================================= - -This project provides first-class OAuth library support for `Requests `_. - -The OAuth 1 workflow --------------------- - -OAuth 1 can seem overly complicated and it sure has its quirks. Luckily, -requests_oauthlib hides most of these and let you focus at the task at hand. - -Accessing protected resources using requests_oauthlib is as simple as: - -.. code-block:: pycon - - >>> from requests_oauthlib import OAuth1Session - >>> twitter = OAuth1Session('client_key', - client_secret='client_secret', - resource_owner_key='resource_owner_key', - resource_owner_secret='resource_owner_secret') - >>> url = 'https://api.twitter.com/1/account/settings.json' - >>> r = twitter.get(url) - -Before accessing resources you will need to obtain a few credentials from your -provider (e.g. Twitter) and authorization from the user for whom you wish to -retrieve resources for. You can read all about this in the full -`OAuth 1 workflow guide on RTD `_. - -The OAuth 2 workflow --------------------- - -OAuth 2 is generally simpler than OAuth 1 but comes in more flavours. The most -common being the Authorization Code Grant, also known as the WebApplication -flow. - -Fetching a protected resource after obtaining an access token can be extremely -simple. However, before accessing resources you will need to obtain a few -credentials from your provider (e.g. Google) and authorization from the user -for whom you wish to retrieve resources for. You can read all about this in the -full `OAuth 2 workflow guide on RTD `_. - -Installation -------------- - -To install requests and requests_oauthlib you can use pip: - -.. code-block:: bash - - $ pip install requests requests_oauthlib - -.. |build-status| image:: https://travis-ci.org/requests/requests-oauthlib.svg?branch=master - :target: https://travis-ci.org/requests/requests-oauthlib -.. |coverage-status| image:: https://img.shields.io/coveralls/requests/requests-oauthlib.svg - :target: https://coveralls.io/r/requests/requests-oauthlib -.. |docs| image:: https://readthedocs.org/projects/requests-oauthlib/badge/ - :alt: Documentation Status - :scale: 100% - :target: https://requests-oauthlib.readthedocs.io/ diff --git a/script.module.requests_oauthlib/addon.xml b/script.module.requests_oauthlib/addon.xml index bd33c8a0a1..9b4bf62a0e 100644 --- a/script.module.requests_oauthlib/addon.xml +++ b/script.module.requests_oauthlib/addon.xml @@ -1,22 +1,20 @@ - - - - - - - - - all - - This project provides first-class OAuth library support for Requests. - This project provides first-class OAuth library support for Requests. - This project provides first-class OAuth library support for Requests. - ISC - https://pypi.org/project/requests-oauthlib - https://github.com/requests/requests-oauthlib - - icon.png - - + + + + + + + + + OAuthlib authentication support for Requests + OAuthlib authentication support for Requests + ISC + all + https://github.com/requests/requests-oauthlib + https://github.com/requests/requests-oauthlib + + resources/icon.png + + diff --git a/script.module.requests_oauthlib/lib/requests_oauthlib/__init__.py b/script.module.requests_oauthlib/lib/requests_oauthlib/__init__.py index a4e03a4e1f..0d3e49f991 100644 --- a/script.module.requests_oauthlib/lib/requests_oauthlib/__init__.py +++ b/script.module.requests_oauthlib/lib/requests_oauthlib/__init__.py @@ -5,7 +5,7 @@ from .oauth2_auth import OAuth2 from .oauth2_session import OAuth2Session, TokenUpdated -__version__ = "1.3.0" +__version__ = "1.3.1" import requests diff --git a/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/__init__.py b/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/__init__.py index 02fa51201a..0e8e3ac84f 100644 --- a/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/__init__.py +++ b/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/__init__.py @@ -2,9 +2,9 @@ from .facebook import facebook_compliance_fix from .fitbit import fitbit_compliance_fix -from .linkedin import linkedin_compliance_fix from .slack import slack_compliance_fix from .instagram import instagram_compliance_fix from .mailchimp import mailchimp_compliance_fix from .weibo import weibo_compliance_fix from .plentymarkets import plentymarkets_compliance_fix +from .ebay import ebay_compliance_fix diff --git a/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/ebay.py b/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/ebay.py new file mode 100644 index 0000000000..4aa423b3fe --- /dev/null +++ b/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/ebay.py @@ -0,0 +1,23 @@ +import json +from oauthlib.common import to_unicode + + +def ebay_compliance_fix(session): + def _compliance_fix(response): + token = json.loads(response.text) + + # eBay responds with non-compliant token types. + # https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html + # https://developer.ebay.com/api-docs/static/oauth-auth-code-grant-request.html + # Modify these to be "Bearer". + if token.get("token_type") in ["Application Access Token", "User Access Token"]: + token["token_type"] = "Bearer" + fixed_token = json.dumps(token) + response._content = to_unicode(fixed_token).encode("utf-8") + + return response + + session.register_compliance_hook("access_token_response", _compliance_fix) + session.register_compliance_hook("refresh_token_response", _compliance_fix) + + return session diff --git a/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/linkedin.py b/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/linkedin.py deleted file mode 100644 index cd5b4ace31..0000000000 --- a/script.module.requests_oauthlib/lib/requests_oauthlib/compliance_fixes/linkedin.py +++ /dev/null @@ -1,21 +0,0 @@ -from json import loads, dumps - -from oauthlib.common import add_params_to_uri, to_unicode - - -def linkedin_compliance_fix(session): - def _missing_token_type(r): - token = loads(r.text) - token["token_type"] = "Bearer" - r._content = to_unicode(dumps(token)).encode("UTF-8") - return r - - def _non_compliant_param_name(url, headers, data): - token = [("oauth2_access_token", session.access_token)] - url = add_params_to_uri(url, token) - return url, headers, data - - session._client.default_token_placement = "query" - session.register_compliance_hook("access_token_response", _missing_token_type) - session.register_compliance_hook("protected_request", _non_compliant_param_name) - return session diff --git a/script.module.requests_oauthlib/lib/requests_oauthlib/oauth1_session.py b/script.module.requests_oauthlib/lib/requests_oauthlib/oauth1_session.py index aa17f28f30..88f2853ca0 100644 --- a/script.module.requests_oauthlib/lib/requests_oauthlib/oauth1_session.py +++ b/script.module.requests_oauthlib/lib/requests_oauthlib/oauth1_session.py @@ -268,7 +268,7 @@ def fetch_request_token(self, url, realm=None, **request_kwargs): :param url: The request token endpoint URL. :param realm: A list of realms to request access to. :param \*\*request_kwargs: Optional arguments passed to ''post'' - function in ''requests.Session'' + function in ''requests.Session'' :returns: The response in dict format. Note that a previously set callback_uri will be reset for your diff --git a/script.module.requests_oauthlib/lib/requests_oauthlib/oauth2_session.py b/script.module.requests_oauthlib/lib/requests_oauthlib/oauth2_session.py index eea4ac6fb8..db4468089b 100644 --- a/script.module.requests_oauthlib/lib/requests_oauthlib/oauth2_session.py +++ b/script.module.requests_oauthlib/lib/requests_oauthlib/oauth2_session.py @@ -189,6 +189,7 @@ def fetch_token( proxies=None, include_client_id=None, client_secret=None, + cert=None, **kwargs ): """Generic method for fetching an access token from the token endpoint. @@ -229,6 +230,10 @@ def fetch_token( `auth` tuple. If the value is `None`, it will be omitted from the request, however if the value is an empty string, an empty string will be sent. + :param cert: Client certificate to send for OAuth 2.0 Mutual-TLS Client + Authentication (draft-ietf-oauth-mtls). Can either be the + path of a file containing the private key and certificate or + a tuple of two filenames for certificate and key. :param kwargs: Extra parameters to include in the token request. :return: A token dict """ @@ -341,6 +346,7 @@ def fetch_token( auth=auth, verify=verify, proxies=proxies, + cert=cert, **request_kwargs ) diff --git a/script.module.requests_oauthlib/icon.png b/script.module.requests_oauthlib/resources/icon.png similarity index 100% rename from script.module.requests_oauthlib/icon.png rename to script.module.requests_oauthlib/resources/icon.png