GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: fix wrong scopes for self signed jwt by arithmetic1728 · Pull Request #935 · googleapis/gapic-generator-python

This repository was archived by the owner on Aug 25, 2026. It is now read-only.

Conversation

@arithmetic1728

@arithmetic1728 arithmetic1728 commented Jun 26, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes: #929

When auth library creates self signed jwt, it looks for scopes, audience and default_scopes in order, and uses the first one available.

In the transport base class, we are using self.AUTH_SCOPES as scopes if scopes are not provided. This is not right.

gapic-generator-python/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2

Line 114 in ceb64d9

self._scopes = scopes or self.AUTH_SCOPES

This is not right since self.AUTH_SCOPES should be only used as default_scopes. self.AUTH_SCOPES may contain only a generic "https://www.googleapis.com/auth/cloud-platform" scope, for instance for all the failed APIs listed in this issue. If it is used as scopes in self signed jwt, the samples may fail with invalid scopes. For the success APIs, the AUTH_SCOPES of kms contains an additional https://www.googleapis.com/auth/cloudkms scope so it has no problem; the other two API are mysterious to me since they are using the same generic scope in AUTH_SCOPES as the failed APIs.

The fix is simple. We just need to change self._scopes = scopes or self.AUTH_SCOPES to self._scopes = scopes in the transport base class. Note that self.AUTH_SCOPES is already passed to grpc channel as default_scopes.

gapic-generator-python/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2

Lines 208 to 217 in ceb64d9

return grpc_helpers.create_channel(
host,
credentials=credentials,
credentials_file=credentials_file,
quota_project_id=quota_project_id,
default_scopes=cls.AUTH_SCOPES,
scopes=scopes,
default_host=cls.DEFAULT_HOST,
**kwargs
)

I tested the PR for all the failed APIs, now all the samples passed (I didn't update the unit test, so kokoro would fail in these PRs):
googleapis/python-speech#189
googleapis/python-asset#215
googleapis/python-videointelligence#171
googleapis/python-analytics-data#95

I also tested the secret_manager and automl APIs, their samples still pass with this fix.
googleapis/python-secret-manager#141
googleapis/python-automl#179

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@arithmetic1728
fix: fix wrong scopes for self signed jwt
fbe1532
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 26, 2021
@arithmetic1728
arithmetic1728 marked this pull request as ready for review June 26, 2021 01:40
@arithmetic1728
arithmetic1728 requested a review from a team June 26, 2021 01:40
@arithmetic1728 arithmetic1728 mentioned this pull request Jun 26, 2021
403 permission denied errors in some libraries with always_use_jwt_access = True #929
Closed
@arithmetic1728
arithmetic1728 requested review from busunkim96, parthea and software-dov June 26, 2021 01:41
This was referenced Jun 26, 2021
chore: release 0.5.1 googleapis/python-pubsublite#171
Closed
chore: release 0.6.0 googleapis/python-pubsublite#173
Merged
chore: release as 1.0.0 googleapis/python-service-directory#82
Merged
feat: add always_use_jwt_access googleapis/python-service-management#28
Closed
chore: release 0.3.0 googleapis/python-service-control#37
Merged
busunkim96
busunkim96 approved these changes Jun 28, 2021
View reviewed changes
@busunkim96 busunkim96 mentioned this pull request Jun 28, 2021
chore(IGNORE): add newlines to README to trigger CI #936
Closed
@arithmetic1728
Merge branch 'master' into jwt_fix
5c52c6c
@arithmetic1728
arithmetic1728 merged commit e033acd into master Jun 28, 2021
@arithmetic1728
arithmetic1728 deleted the jwt_fix branch June 28, 2021 17:00
This was referenced Jan 18, 2022
chore(master): release reverted #1133
Merged
chore(master): release 0.40.0 #1138
Closed
chore(master): release 0.39.1 #1146
Closed
This was referenced Jan 26, 2022
chore(main): release 0.39.1 #1160
Closed
chore(main): release 0.39.1 #1162
Closed
chore(main): release 0.61.0 #1163
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@parthea parthea Awaiting requested review from parthea
@software-dov software-dov Awaiting requested review from software-dov
1 more reviewer
@busunkim96 busunkim96 busunkim96 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

403 permission denied errors in some libraries with always_use_jwt_access = True

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@arithmetic1728 @busunkim96
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.