Authorize Requests

Every request your application sends to the G Suite Email Audit API must include an authorization token. The token also identifies your application to Google.

About authorization protocols

Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you.

Authorizing requests with OAuth 2.0

All requests to the G Suite Email Audit API must be authorized by an authenticated user.

The details of the authorization process, or "flow," for OAuth 2.0 vary somewhat depending on what kind of application you're writing. The following general process applies to all application types:

  1. When you create your application, you register it using the Google API Console. Google then provides information you'll need later, such as a client ID and a client secret.
  2. Activate the G Suite Email Audit API in the Google API Console. (If the API isn't listed in the API Console, then skip this step.)
  3. When your application needs access to user data, it asks Google for a particular scope of access.
  4. Google displays a consent screen to the user, asking them to authorize your application to request some of their data.
  5. If the user approves, then Google gives your application a short-lived access token.
  6. Your application requests user data, attaching the access token to the request.
  7. If Google determines that your request and the token are valid, it returns the requested data.

Some flows include additional steps, such as using refresh tokens to acquire new access tokens. For detailed information about flows for various types of applications, see Google's OAuth 2.0 documentation.

Here's the OAuth 2.0 scope information for the G Suite Email Audit API:

Scopes Meaning Global scope for access to audit user accounts

To request access using OAuth 2.0, your application needs the scope information, as well as information that Google supplies when you register your application (such as the client ID and the client secret).

Generating a public key

The Email Audit API provides the ability to upload an OpenPGP Public Encryption Key for the domain. This step is done once when setting up the mailbox download. The domain administrators can generate the public/private key pair using any OpenPGP-compatible software, such as GNU Privacy Guard (GPG) software. Go to the GNUPG site to download a free version of PGP implementation for both UNIX and Windows environments. This public encryption key should be a PGP format ASCII-encoded RSA key. If using the GPG implementation, you need to specify the --gen-key --expert flags in order to generate an RSA encryption key (Option 8 on the GPG menu). This key should have the Encrypt action enabled. You can turn off the Sign action, as it will not be used.

Export the public part of the key using gpg --armor --export. Note you should only export the key for the user id that corresponds to your G Suite domain. If you have already used GPG to generate other keys, you will have multiple keys in your keyring. To verify this, use gpg --list-keys. If multiple keys are listed, you will need to specify the uid of the key that you want to export, using gpg --armor --export key_uid. This key will be used to encrypt the mailbox export files before being made available for downloads. Once the administrator downloads the requested files, decrypt the files using the private encryption key. If using the GPG implementation, this is done by running gpg -d. The final mailbox export files are in mbox format.

Before uploading the public key, convert it to a base64 encoded string. The public key file should be read with the charset US-ASCII, (IANA preferred charset name for ASCII). For example, if the PGP public key file looks like this:

Version: GnuPG v1.4.10 (GNU/Linux)


Note: The PGP block should contain only a single key. Even though it is possible to have multiple keys in a single GPG-compliant message, the API only supports one key. With GPG, you can use the gpg --list-keys command to list all of the key signatures.

Read this file with US-ASCII charset file and encode it to a base64 string. The encoding process can be performed by using the free tool at For the public key example above, the base64 encoded string looks like:



Note: Invalid OpenPGP keys are generally the most common cause of errors. This is a summary of the step-by-step instructions to generate a public key for the Email Audit API:

1. install GNUPG.
2. run gpg --gen-key --expert to generate a new key, selecting option 8 "RSA (set your own capabilities)" and toggling the sign capability.
3. accept all default options to complete the key generation process.
4. run gpg --armor --export to export the key. Please make sure you are only exporting the single key you just generated.
5. visit to base64-encode the key. Double check you are copying all the lines, including the header and not adding any extra line.

Uploading the public key

To upload the public key, start by creating an XML entry with the base64 encoded public key as shown in the example below:

<atom:entry xmlns:atom='' xmlns:apps=''>
<apps:property name="publicKey" value="the base64 Encoded Key"/>

Send an HTTP POST request to the 'publickey' feed URI in your G Suite domain:

POST{domain name}

If successful, the server returns a 201 CREATED status code found in the Google Data API HTTP status codes documentation. Along with the status code, the response is similar to this example:

<entry xmlns:atom='' xmlns:apps=''>
<id> domain/id>/id>
<link rel='self' type='application/atom+xml' href=' domain/id'/>
<link rel='edit' type='application/atom+xml' href=' domain/id'/>
<apps:property name='publicKey' value='base64 encoded public key'/>

An attempt to upload an invalid key will return with error code 1411 (EncryptionPublicKeyInvalidFormat).

If, at a later time, the Email Audit API is called with a different public key, the old key is replaced by the latest key. All the future encryptions will use the latest key.

다음에 대한 의견 보내기...

도움이 필요하시나요? 지원 페이지를 방문하세요.