googleapis / gax-python

Google API Extensions for Python
http://gax-python.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
25 stars 13 forks source link

Upgrade credentials to JWT-based credentials if appropriate #177

Open theacodes opened 7 years ago

theacodes commented 7 years ago

Some APIs can benefit from using JWT-based credentials over OAuth 2.0-based credentials. Those APIs should upgrade to jwt.OnDemandCredentials if they are provided an instance of google.auth.credentials.Signing.

So, for example:

credentials, _ = google.auth.default()

if isinstance(credentials, google.auth.credentials.Signing):
    jwt_credentials = google.auth.jwt.OnDemandCredentials.from_signing_credentials(credentials)