You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To support CI workflows building off gh actions, I'd like to use the recommended auth method using google.auth.default with google-github-actions/auth@v0.4.0 - https://github.com/google-github-actions/auth.
This would (hopefully) allow the following, using the more modern google.auth lib:
gauth = GoogleAuth()
try:
gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name(LOCAL_KEY, SCOPES) # support local dev
except FileNotFoundError:
credentials, _ = google.auth.default(SCOPES) # prod
gauth.credentials = credentials
hey @jonathanelscpt, the GoogleAuth in this library supports file-based service auth through:
specifying the service credential file name in the yaml config under service_config > client_json_file_pathor specifying the GOOGLE_APPLICATION_CREDENTIALS environment variable and setting service_config > use_default = True
instantiate GoogleAuth
run the ServiceAuth method which would:
reads the service credential json path
use the from_service_account_file class method (see here) to create the service account credentials
At least, this is how it would be after my pull request above has been merged. Because the entire library's google auth is driven by the .yaml config file, I've kept to the same design whilst I was working to migrate from oauth2client -> google-auth
For the record, current implementation supports reading from a dict, from ENV, etc. I'm not sure about the default credentials. It depends on the underlying implementation for them.
The credential assignment in the original example is supported on main through #395, pending release. Call credentials, _ = google.auth.default(scopes=["https://www.googleapis.com/auth/drive"]) and assign gauth.credentials = credentials before using GoogleDrive(gauth). I verified that path with a mocked Drive request. Automatic discovery by PyDrive2 itself is tracked in #187.
Activity
fatestapestry commentedon May 29, 2022
@junpeng-jp will test after merge
fatestapestry commentedon May 29, 2022
Fixing this should also support:
fatestapestry commentedon May 30, 2022
A working alternative until this is implemented is to use this after reading key from env:
oauth2client.service_account.ServiceAccountCredentials.from_json_keyfile_dict()junpeng-jp commentedon May 30, 2022
hey @jonathanelscpt, the GoogleAuth in this library supports file-based service auth through:
service_config > client_json_file_pathor specifying theGOOGLE_APPLICATION_CREDENTIALSenvironment variable and settingservice_config > use_default=Truefrom_service_account_fileclass method (see here) to create the service account credentialsjunpeng-jp commentedon May 30, 2022
At least, this is how it would be after my pull request above has been merged. Because the entire library's google auth is driven by the .yaml config file, I've kept to the same design whilst I was working to migrate from oauth2client -> google-auth
shcheklein commentedon Nov 13, 2022
For the record, current implementation supports reading from a dict, from ENV, etc. I'm not sure about the default credentials. It depends on the underlying implementation for them.
shcheklein commentedon Nov 21, 2026
The credential assignment in the original example is supported on
mainthrough #395, pending release. Callcredentials, _ = google.auth.default(scopes=["https://www.googleapis.com/auth/drive"])and assigngauth.credentials = credentialsbefore usingGoogleDrive(gauth). I verified that path with a mocked Drive request. Automatic discovery by PyDrive2 itself is tracked in #187.