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.

Add on-demand jwt credentials #136

@theacodes

Description

@theacodes

jwt.Credentials only works for a single audience at a time and must have knowledge of the audience beforehand. gRPC APIs, however, may not be able to determine the audience beforehand so JWTs should be generated on-demand during the before_request callback.

We previously had this behavior as part of jwt.Credentials, but it was removed because it made the behavior of the class ambiguous. This feature request is to bring that functionality back as a separate class jwt.OnDemandCredentials.

This class:

  • Doesn't accept an audience argument in its constructor.
  • Can be created from existing credentials using from_signing_credentials.
  • Holds a cache of JWTs for specific audiences using cachetools.LRUCache.
  • Generates a new JWT for the specific audience in before_request or uses an existing cached JWT.
  • Is always valid and never expires but never has a token.

Context.

@dhermes @lukesneeringer any concerns about the name or dependency on cachetools?
@jboeuf any concerns on the behavior here?

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.triage meI really want to be triaged.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions