Search code examples
oauth-2.0google-oauthgoogle-api-python-clientservice-accounts

How to refresh credentials from google.oauth2.service_account.Credentials object?


I have an instance of google.oauth2.service_account.Credentials. How should I refresh these credentials. I get creds.expired as True.


Solution

  • While reading the docs here, I got my answer. WE can refresh the credentials and get the token using following approach :

    import google.auth.transport.requests
    import requests
    
    request = google.auth.transport.requests.Request()
    
    credentials.refresh(request)