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

Token refresh on each API request when using UserAccessTokenCredentials #1341

@bzurkowski

Description

@bzurkowski

I observed that requests to Google Cloud APIs take much longer when using UserAccessTokenCredentials (documented here) as credentials for client libraries, e.g., Storage library for Python.

Diving into the code, I realized that UserAccessTokenCredentials triggers token refresh (resulting in an additional API request) on each request due to how the before_request method is implemented:

def before_request(self, request, method, url, headers):
    self.refresh(request)
    self.apply(headers)

In comparison, the before_request method in the base class has a mechanism to trigger token refresh only when necessary:

if not self.valid:
    self.refresh(request)

Would it be reasonable to check token validity before request in the UserAccessTokenCredentials strategy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions