gdata.apps.audit.service authentication without ClientLogin

189 Views Asked by At

I want to utilize gdata.apps.audit.service.AuditService to create mailbox export requests (specifically via createMailboxExportRequest). Is it possible to access this api authenticating via oauth or another means? I'm trying to avoid requiring a user to provide a username and password.

Here is an example piece of code:

audit_service = gdata.apps.audit.service.AuditService(domain="test.com")

#would like to not use ClientLogin
client = audit_service.ClientLogin("[email protected]", "superSecretPassword") # <------
audit_service.createMailboxExportRequest(user="target_user", begin_date=None, end_date=None,     include_deleted=True, search_query=None)
audit_service.getAllMailboxExportRequestsStatus()

I'm successfully using oauth2/client_secrets for other admin/audit APIs but I can't figure out how to get the createMailboxExportRequest without ClientLogin. Any help would be appreciated.

1

There are 1 best solutions below

0
On

The easiest way I've found to hack OAuth 2.0 into the older GData APIs is to build the GData service (but not authorize it), then build a credentials service like you would for the newer OAuth 2.0 discovery Google APIs, then add the proper credentials as a header on the GData service:

audit_service = gdata.apps.audit.service.AuditService(domain="test.com")
...   # build your credentials like normal with oauth2client
auth_headers = {u'Authorization': u'Bearer %s' % credentials.access_token}
audit_service.additional_headers = auth_headers