From 20f82e22b7e8c6c7fdd29e08eaf7b4cf2abdcf37 Mon Sep 17 00:00:00 2001 From: Kenji Imamula Date: Fri, 31 Jul 2020 05:40:02 +0900 Subject: [PATCH 1/3] fix: set Content-Type header in the request to signBlob API to avoid Invalid JSON payload error (#439) `auth.create_custom_token()` results in an error: ``` Failed to sign custom token. Error calling the IAM signBytes API:{ (...) "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \"{\"bytesToSign\": \"...\"}\": Cannot bind query parameter. Field '{\"bytesToSign\": \"...\"}' could not be found in request message.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "description": "Invalid JSON payload received. Unknown name \"{\"bytesToSign\": \"...\"}\": Cannot bind query parameter. Field '{\"bytesToSign\": \"...\"}' could not be found in request message." } ] } ] } } ``` I have confirmed setting `'Content-Type': 'application/json'` header resolves the problem. --- google/auth/iam.py | 2 +- tests/test_iam.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/google/auth/iam.py b/google/auth/iam.py index bd0500457..d83b25180 100644 --- a/google/auth/iam.py +++ b/google/auth/iam.py @@ -69,7 +69,7 @@ def _make_signing_request(self, message): method = "POST" url = _SIGN_BLOB_URI.format(self._service_account_email) - headers = {} + headers = {"Content-Type": "application/json"} body = json.dumps( {"bytesToSign": base64.b64encode(message).decode("utf-8")} ).encode("utf-8") diff --git a/tests/test_iam.py b/tests/test_iam.py index 4367fe7a8..cb2c26f73 100644 --- a/tests/test_iam.py +++ b/tests/test_iam.py @@ -89,6 +89,8 @@ def test_sign_bytes(self): returned_signature = signer.sign("123") assert returned_signature == signature + kwargs = request.call_args.kwargs + assert kwargs["headers"]["Content-Type"] == "application/json" def test_sign_bytes_failure(self): request = make_request(http_client.UNAUTHORIZED) From 42321bafd38a8bd806f4d01bfa0eda3b5a961667 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Thu, 6 Aug 2020 16:50:06 -0700 Subject: [PATCH 2/3] fix: reduce refresh clock skew to 10 seconds (#581) --- google/auth/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/auth/_helpers.py b/google/auth/_helpers.py index ecb88ffda..21c987a73 100644 --- a/google/auth/_helpers.py +++ b/google/auth/_helpers.py @@ -22,7 +22,7 @@ from six.moves import urllib -CLOCK_SKEW_SECS = 300 # 5 minutes in seconds +CLOCK_SKEW_SECS = 10 # 10 seconds CLOCK_SKEW = datetime.timedelta(seconds=CLOCK_SKEW_SECS) From ae27b49468c5c3db99d0550af9066ca43cb0dda7 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2020 16:59:19 -0700 Subject: [PATCH 3/3] chore: release 1.20.1 (#582) * chore: updated CHANGELOG.md [ci skip] * chore: updated setup.cfg [ci skip] * chore: updated setup.py Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 8 ++++++++ setup.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7e71f265..56faf8efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ [1]: https://pypi.org/project/google-auth/#history +### [1.20.1](https://www.github.com/googleapis/google-auth-library-python/compare/v1.20.0...v1.20.1) (2020-08-06) + + +### Bug Fixes + +* reduce refresh clock skew to 10 seconds ([#581](https://www.github.com/googleapis/google-auth-library-python/issues/581)) ([42321ba](https://www.github.com/googleapis/google-auth-library-python/commit/42321bafd38a8bd806f4d01bfa0eda3b5a961667)) +* set Content-Type header in the request to signBlob API to avoid Invalid JSON payload error ([#439](https://www.github.com/googleapis/google-auth-library-python/issues/439)) ([20f82e2](https://www.github.com/googleapis/google-auth-library-python/commit/20f82e22b7e8c6c7fdd29e08eaf7b4cf2abdcf37)) + ## [1.20.0](https://www.github.com/googleapis/google-auth-library-python/compare/v1.19.2...v1.20.0) (2020-07-23) diff --git a/setup.py b/setup.py index 5b192b10a..cfa7b0a85 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ with io.open("README.rst", "r") as fh: long_description = fh.read() -version = "1.20.0" +version = "1.20.1" setup( name="google-auth",