googledrive/PyDrive — pull request #19 by pzingg (2014-06-07 00:50:38+00:00)
Title: Support for service account authentication

I would like to use GDrive as a super-user, and be able to access many user accounts in the Google Apps domain I administer. This requires a slightly different authentication flow:

See https://developers.google.com/drive/web/delegation

I have added a few new settings and a ServiceAccountAuth method. If the service_account setting is True, and the service_account_email and service_account_key_file settings are specified, the CheckAuth decorator will load the credential information by using a new LoadServiceAccountCredentials method and then goes straight to Authorize. Perhaps I didn't factor this as best as possible.

The ServiceAccountAuth takes a parameter that is the "sub_user" to authenticate as in GDrive. I think the logic works where you can call gauth.ServiceAccountAuth(sub_user) with different sub_users, and the access token is revoked before re-authorizing.

I have it working with a test project I wrote at https://github.com/ksdtech/gdrive-audit

I didn't update your docs system or write new tests (which of course I should have).

I also tried pulling the required service account email address from the client_secrets.json file you get from the Google Developer Console. There is a "client_email" key in the client_secrets.json file, but the google oauth2client.clientsecrets module flags the file as incorrect, because it doesn't contain a "client_secret" key for the type "web" ("client_secret" is not needed for service accounts, but the type is still "web"). So rather then rewriting the validation for that, I just put a "service_account_email" key in the settings.yaml file.