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 — feat: support self-signed jwt in requests and urllib3 transports by busunkim96 · Pull Request #679 · googleapis/google-auth-library-python

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

Conversation

@busunkim96

@busunkim96 busunkim96 commented Feb 3, 2021

Copy link
Copy Markdown
Contributor

Follow up to #665.

Allow self-signed JWT flow to be used in the requests and urllib3 transports if a default_host is provided. I don't think any of our clients wrap the urllib3 transport, but a good number of handwritten libraries (Storage for example) uses AuthorizedSession from requests.

Sorry, something went wrong.

Uh oh!

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

All reactions
busunkim96 added 2 commits February 3, 2021 02:35
@busunkim96
feat: support self-signed-jwt in requests and urllib3 transports
3aeda3a
@busunkim96
chore: lint
7b2432e
@busunkim96
busunkim96 requested review from a team, arithmetic1728 and bshaffer February 3, 2021 02:42
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Feb 3, 2021
busunkim96
busunkim96 commented Feb 3, 2021
View reviewed changes
Comment thread system_tests/system_tests_sync/test_requests.py
Comment on lines +21 to +40
def test_authorized_session_with_service_account_and_self_signed_jwt():
credentials, project_id = google.auth.default()

credentials = credentials.with_scopes(
scopes=[],
default_scopes=["https://www.googleapis.com/auth/pubsub"],
)

session = google.auth.transport.requests.AuthorizedSession(
credentials=credentials, default_host="pubsub.googleapis.com"
)

# List Pub/Sub Topics through the REST API
# https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/list
response = session.get("https://pubsub.googleapis.com/v1/projects/{}/topics".format(project_id))
response.raise_for_status()

# Check that self-signed JWT was created and is being used
assert credentials._jwt_credentials is not None
assert credentials._jwt_credentials.token == credentials.token

@busunkim96 busunkim96 Feb 3, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried to write this test with the Storage API, but requests seemed to fail with invalid credentials (a test with the service account passed).

Are there any APIs where the self-signed JWT approach won't work? @bshaffer

Sorry, something went wrong.

Uh oh!

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

All reactions
arithmetic1728
arithmetic1728 reviewed Feb 3, 2021
View reviewed changes
Comment thread google/auth/transport/requests.py
refreshing credentials. If not passed,
an instance of :class:`~google.auth.transport.requests.Request`
is created.
default_host (Optional[str]): A host like "pubsub.googleapis.com".

@arithmetic1728 arithmetic1728 Feb 3, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a little bit concern about setting the default_host in ctor. There are 2 default endpoints, for instance, pubsub.googleapis.com and pubsub.mtls.googleapis.com. mtls has auto switch logic to switch from the regular endpoint to mtls endpoint. It works as follows:

(1) client creates an AuthorizedSession
(2) client calls AuthorizedSession.is_mtls (with other conditions like the GOOGLE_API_USE_CLIENT_CERTIFICATE env var) to decide which endpoint to use

So this means in the AuthorizedSession ctor, we may not know exactly which default endpoint will be used. So if both endpoints use the regular endpoint as the audience, then this code works fine. Otherwise, we need to find a way.

@bshaffer

Sorry, something went wrong.

Uh oh!

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

busunkim96 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@arithmetic1728 arithmetic1728 Feb 3, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mtls only works with user credentials, so this should be fine since service account credentials will be rejected by the server anyway.

Sorry, something went wrong.

Uh oh!

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

All reactions
arithmetic1728
arithmetic1728 approved these changes Feb 3, 2021
View reviewed changes

@arithmetic1728 arithmetic1728 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
@busunkim96
test: fix filename for urllib3 system test
bd441d8
@busunkim96 busunkim96 changed the title feat: support self-signed-jwt in requests and urllib3 transports feat: support self-signed jwt in requests and urllib3 transports Feb 3, 2021
@busunkim96 busunkim96 changed the title feat: support self-signed jwt in requests and urllib3 transports feat: support self-signed jwt in requests and urllib3 transports Feb 3, 2021
@busunkim96 busunkim96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 3, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 3, 2021
@busunkim96
busunkim96 merged commit 7a94acb into master Feb 3, 2021
@busunkim96
busunkim96 deleted the self-signed-jwt-requests branch February 3, 2021 23:57
@busunkim96 busunkim96 mentioned this pull request Jan 12, 2026
Add self-signed JWT support to async credentials googleapis/google-cloud-python#15219
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@bshaffer bshaffer Awaiting requested review from bshaffer
1 more reviewer
@arithmetic1728 arithmetic1728 arithmetic1728 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.

Uh oh!

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

3 participants

@busunkim96 @arithmetic1728 @yoshi-kokoro
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.