Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async certificate retrieving - problem still exists #1100

Closed
tivaliy opened this issue Aug 6, 2022 · 0 comments
Closed

Async certificate retrieving - problem still exists #1100

tivaliy opened this issue Aug 6, 2022 · 0 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@tivaliy
Copy link
Contributor

tivaliy commented Aug 6, 2022

After the latest release the problem of retrieving certificate still exists for async mode. Here is the previous fix - #1050

Environment details

  • Python version: Python 3.9
    • pip version: 22.1.2
    • google-auth version: 2.10.0

Steps to reproduce

In [1]: from google.oauth2 import _id_token_async

In [2]: from google.auth.transport import _aiohttp_requests

In [3]: certs_url = "https://www.googleapis.com/oauth2/v1/certs"

In [4]: request = _aiohttp_requests.Request()

In [5]: response = await request(certs_url, method="GET")

In [6]: response.status
Out[6]: 200

In [7]: data = await response.data.read()

In [8]: import json

In [9]: json.loads(data.decode("utf-8"))
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
Input In [10], in <cell line: 1>()
----> 1 json.loads(data.decode("utf-8"))

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

I suppose that the problem is in 'Content-Encoding': 'gzip' (response), which is not supported by Request (

):

    def __init__(self, session=None):
        # TODO: Use auto_decompress property for aiohttp 3.7+
        if session is not None and session._auto_decompress:
            raise ValueError(
                "Client sessions with auto_decompress=True are not supported."
            )
        self.session = session

instead, the following code should be used:

In [12]: response = await request(certs_url, method="GET")

In [13]: data = await response.content()

In [14]: json.loads(data)
Out[14]:
{'fda1066453dc9dc3dd933a41ea57da3ef242b0f7': '-----BEGIN CERTIFICATE-----\nMIIDJzCCAg+gAwIBAgIJAIVR59GV94ZKMA0GCSqGSIb3DQEBBQUAMDYxNDAyBgNV\nBAMMK2ZlZ
...........................
 '1549e0aef574d1c7bdd136c202b8d290580b165c': '-----BEGIN CERTIFICATE-----\nMIIDJzCCAg+gAwIBAgIJAOdJ975Uc0N7MA0GCSqGSIb3DQEBBQUAMDYxNDAyBgNV\nBAMMK2ZlZGVyYXRlZC1zaWdub24uc
...........................
e3K0wtBfTrXA/xhJq\nhB+S3TlXx9ZZvvl8UR51TqiQu99X9dzjMateAA9ajeQUMJKgVs7+ojQtyQ==\n-----END CERTIFICATE-----\n'}
@clundin25 clundin25 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants