Created
December 20, 2021 16:39
-
-
Save salrashid123/6dc299c6a901e826fa5cf6d96a4c4e75 to your computer and use it in GitHub Desktop.
google.auth.StaticCredentils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## StaticCredentials should be in google.auth. | |
# sc = StaticCredentials(token=access_token,expires_in=expires_in,token_type=token_type) | |
# from google.cloud import storage | |
# client = storage.Client(project=project, credentials=sc) | |
# for b in client.list_buckets(): | |
# print(b.name) | |
from datetime import datetime, timedelta | |
from google.auth import _helpers | |
from google.auth import credentials | |
from google.auth import exceptions | |
import requests | |
class StaticCredentials(credentials.Credentials): | |
def __init__( | |
self, | |
token, | |
expires_in, | |
token_type, | |
): | |
super(credentials.Credentials, self).__init__() | |
self.token = token | |
if token == None: | |
raise exceptions.GoogleAuthError( | |
"Provided token cannot be null" | |
) | |
self.token_type = token_type | |
self.expiry = datetime.now() + timedelta(seconds=int(expires_in)) | |
self._quota_project_id = None | |
@_helpers.copy_docstring(credentials.Credentials) | |
def refresh(self, request): | |
return | |
@property | |
def expired(self): | |
return _helpers.utcnow() >= self.expiry | |
@property | |
def quota_project_id(self): | |
"""Project to use for quota and billing purposes.""" | |
return self._quota_project_id | |
## StaticCredentials should be in google.auth. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment