-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistDevices.py
38 lines (27 loc) · 1.29 KB
/
listDevices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Lists devices in a Google Workspace domain.
* @see https://cloud.google.com/identity/docs/how-to/setup-devices
*/
from google.oauth2 import service_account
import googleapiclient.discovery
from pprint import pprint
# Scopes required by this endpoint -> https://cloud.google.com/identity/docs/reference/rest/v1/devices/list
SCOPES = ['https://www.googleapis.com/auth/cloud-identity.devices',
'https://www.googleapis.com/auth/cloud-identity',
'https://www.googleapis.com/auth/cloud-identity.devices.readonly']
# Service Account Credentials to be used. How to create at https://developers.google.com/workspace/guides/create-credentials#service-account
SERVICE_ACCOUNT_FILE = 'deviceskey.json'
def create_service():
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
#Google Workspace Super Admin user account to be impersonated to retrieve the list of devices
delegated_credentials = credentials.with_subject('[email protected]')
service_name = 'cloudidentity'
api_version = 'v1'
service = googleapiclient.discovery.build(
service_name,
api_version,
credentials=delegated_credentials)
return service
results = create_service().devices().list().execute()
pprint(results)