Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 14e7765

Browse files
nicainparthea
andauthored
fix(v1beta2): enable self signed jwt for grpc (#191)
* fix: Remove Owlbot v1beta2 customization that passes default scopes as user scopes, so that the auth library does not use the self-signed JWT flow. * run owlbot locally * remove replacements for v1beta2 in owlbot.py Co-authored-by: Nick Cain <nicholascain@google.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent fbc19bb commit 14e7765

3 files changed

Lines changed: 3 additions & 34 deletions

File tree

google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,7 @@ def _get_scopes_kwargs(
148148
packaging.version.parse(_GOOGLE_AUTH_VERSION)
149149
>= packaging.version.parse("1.25.0")
150150
):
151-
# Documentai uses a regional host (us-documentai.googleapis.com) as the default
152-
# so self-signed JWT cannot be used.
153-
# Intentionally pass default scopes as user scopes so the auth library
154-
# does not use the self-signed JWT flow.
155-
# https://github.com/googleapis/python-documentai/issues/174
156-
scopes_kwargs = {
157-
"scopes": scopes or cls.AUTH_SCOPES,
158-
"default_scopes": cls.AUTH_SCOPES,
159-
}
151+
scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES}
160152
else:
161153
scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES}
162154

owlbot.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,11 @@
3030
for library in s.get_staging_dirs(default_version):
3131
excludes = [
3232
"README.rst",
33-
"nox.py",
3433
"docs/index.rst",
3534
"setup.py",
3635
"scripts/fixup_documentai_v*", # this library was always generated with the microgenerator
3736
]
3837

39-
s.replace(library / "google/cloud/documentai_v1beta2/**/base.py",
40-
"""scopes_kwargs = \{"scopes": scopes, "default_scopes": cls\.AUTH_SCOPES\}""",
41-
"""# Documentai uses a regional host (us-documentai.googleapis.com) as the default
42-
# so self-signed JWT cannot be used.
43-
# Intentionally pass default scopes as user scopes so the auth library
44-
# does not use the self-signed JWT flow.
45-
# https://github.com/googleapis/python-documentai/issues/174
46-
scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES, "default_scopes": cls.AUTH_SCOPES}""")
47-
48-
s.replace(library / "tests/**/documentai_v1beta2/*.py",
49-
"""(@requires_google_auth_gte_1_25_0
50-
def test_document_.*?_service_base_transport_with_credentials_file.*?)scopes=None,""",
51-
"""\g<1>scopes=("https://www.googleapis.com/auth/cloud-platform",),""",
52-
flags=re.MULTILINE | re.DOTALL,
53-
)
54-
55-
s.replace(library / "tests/**/documentai_v1beta2/*.py",
56-
"""(@requires_google_auth_gte_1_25_0
57-
def test_document_.*?_service_auth_adc.*?)scopes=None,""",
58-
"""\g<1>scopes=("https://www.googleapis.com/auth/cloud-platform",),""",
59-
flags=re.MULTILINE | re.DOTALL,
60-
)
6138
s.move(library, excludes=excludes)
6239

6340
s.remove_staging_dirs()

tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ def test_document_understanding_service_base_transport_with_credentials_file():
10451045
)
10461046
load_creds.assert_called_once_with(
10471047
"credentials.json",
1048-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
1048+
scopes=None,
10491049
default_scopes=("https://www.googleapis.com/auth/cloud-platform",),
10501050
quota_project_id="octopus",
10511051
)
@@ -1089,7 +1089,7 @@ def test_document_understanding_service_auth_adc():
10891089
adc.return_value = (ga_credentials.AnonymousCredentials(), None)
10901090
DocumentUnderstandingServiceClient()
10911091
adc.assert_called_once_with(
1092-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
1092+
scopes=None,
10931093
default_scopes=("https://www.googleapis.com/auth/cloud-platform",),
10941094
quota_project_id=None,
10951095
)

0 commit comments

Comments
 (0)