Created
August 9, 2017 21:20
-
-
Save dcosson/4e22bbe4965de533c4082ed3319991f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import json | |
import os | |
from googleapiclient import discovery | |
from oauth2client.service_account import ServiceAccountCredentials | |
def authenticated_directory_service(delegate_user_email): | |
""" Returns a service object for accessing the admin directory service. | |
""" | |
json_creds = json.loads(os.environ['GOOGLE_KEYFILE_JSON']) | |
credentials = ServiceAccountCredentials.from_json_keyfile_dict( | |
json_creds, | |
scopes=["https://www.googleapis.com/auth/admin.directory.user.readonly"]) | |
credentials_delegated = credentials.create_delegated(delegate_user_email) | |
service = discovery.build('admin', 'directory_v1', credentials=credentials_delegated) | |
return service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment