GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat: support self-signed JWT flow for service accounts by busunkim96 · Pull Request #774 · googleapis/gapic-generator-python
This repository was archived by the owner on Aug 25, 2026. It is now read-only.
Conversation
|
Codecov Report
@@ Coverage Diff @@ ## master #774 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 26 27 +1 Lines 1608 1653 +45 Branches 328 337 +9 ========================================= + Hits 1608 1653 +45
Continue to review full report at Codecov.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
d696ce3 to
f154176
Compare
| if host != self.DEFAULT_HOST and not scopes: | ||
| scopes = self.AUTH_SCOPES |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If port is provided (say pubsub.googleapis.com:443 instead of pubsub.googleapis.com) the library will think the OAuth2 flow is necessary.
I initially tried splitting on : but that broke the showcase tests where default host is localhost. Is there a better way to parse the provided host reliably?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Silly questions: which is the OAuth2 flow, and why do we not want it all the time? Is it the "old style"? What are we trying to parse out? We can always fall back to regexes, something like
host_re = re.compile("(?P<host>[^:]+)(:(?P<port>\d+))?")
Or is that not the part of parsing out the host that's problematic?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry for being vague.
The OAuth2 flow (currently always used for service accounts) requires a call out to oauth2.googleapis.com. With a service account, it's sometimes possible to "self-sign" the token, which avoids a network round trip.
The self-signed JWT option can be used when:
Number 4 is what's relevant here. If the user is using the non-default endpoint we want to make sure the auth library uses OAuth2. The suggested way to do this in the doc is to pass user scopes to the auth library.
I think that regex will work! I'll experiment and push a new commit.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is quite the endeavor. Thanks for doing it!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if host != self.DEFAULT_HOST and not scopes: | ||
| scopes = self.AUTH_SCOPES |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Silly questions: which is the OAuth2 flow, and why do we not want it all the time? Is it the "old style"? What are we trying to parse out? We can always fall back to regexes, something like
host_re = re.compile("(?P<host>[^:]+)(:(?P<port>\d+))?")
Or is that not the part of parsing out the host that's problematic?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
FYI, cl/357773081 is submitted, so I guess custom endpoint will no longer be an issue for self signed JWT going forward. @bshaffer |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@bshaffer Would you be able to take a look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
This is true but it still will be some time before it rolls out. It's up to the owners of this repo if that's acceptable to wait for the rollout or go ahead with the fix we have here. I'd prefer the latter. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yep, agreed, it is just a FYI. It still takes one or two weeks for the roll out. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
75472e0 to
38c3b18
Compare
|
@bshaffer PTAL. :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Does @bshaffer need to take a look, or is this good to merge? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@bshaffer or @arithmetic1728 would you mind taking another look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@bshaffer I removed the scope override with custom endpoints to match guidance in https://docs.google.com/document/d/1FoJPYQu8ZHdGBFY9TBRZCDrWJJnxw3fAz5CG5mdZR9E/edit. Could you take a look?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@software-dov Could you take one more look? Thank you for your help getting this over the line. :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
One question I still have is, unfortunately, for the case of the regional endpoint us-documentai.googleapis.com, we need a check to make sure the DEFAULT_HOST doesn't contain a regional endpoint.
If this is something we should do here, or somewhere else, I am not sure, I just want to verify it's being considered!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| # Save the scopes. | ||
| self._scopes = scopes_kwargs["scopes"] | ||
| self._scopes = scopes or self.AUTH_SCOPES |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding this correctly, scopes_kwargs["scopes"] was essentially scopes but with a check for if the endpoint was supplied. And I am interpreting scopes or self.AUTH_SCOPES to mean "user supplied scopes or the default scopes"
Is that accurate?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yep! Since the endpoint restriction has been lifted I went back to "user supplied scopes or the default scopes"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
|
|
||
| @classmethod | ||
| def _get_user_scopes(cls, host: str, scopes: Optional[Sequence[str]]) -> Optional[Sequence[str]]: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@bshaffer From reading the doc it seems like documentai is the exception, so I am planning on handling that with a synthtool/owlbot replace. If we anticipate more APIs using the regional endpoints as the default host I can build logic into the generator. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
That sounds great! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
🤖 I have created a release \*beep\* \*boop\* --- ## [0.44.0](https://www.github.com/googleapis/gapic-generator-python/compare/v0.43.3...v0.44.0) (2021-04-23) ### Features * support self-signed JWT flow for service accounts ([#774](https://www.github.com/googleapis/gapic-generator-python/issues/774)) ([89d6f35](https://www.github.com/googleapis/gapic-generator-python/commit/89d6f35c54b0a9b81c9b5f580d2e9eb87352ed93)) ### Bug Fixes * enable GAPIC metadata generation ([#843](https://www.github.com/googleapis/gapic-generator-python/issues/843)) ([697816c](https://www.github.com/googleapis/gapic-generator-python/commit/697816ce7d5b201d6ced85fadd89f9140da67b37)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.