Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.