= Google API Testing

The tests accessing Google API require a Google account, whose credentials cannot be shared with the world in this git repository.
Those tests are thus skipped unless you set the following environment variables:

[source,shell]
----
export GOOGLE_API_APPLICATION_NAME="..."
export GOOGLE_API_CLIENT_ID="..."
export GOOGLE_API_CLIENT_SECRET="..."
export GOOGLE_API_REFRESH_TOKEN="..."
----


== Obtain Google API credentials

=== Red Hatters

There is a Google account called `camel.itest` whose credentials are accessible to Red Hat engineers and to Fusesource Jenkins running internally at Red Hat.

=== Setup from scratch

If you do not have an access to the above credentials, or if you want to start from scratch, here is how:

1. Create a new Google account or take an existing. In what follows, we will re refer to this account as `john-the-tester`.

2. Being logged in to Google as `john-the-tester`, go to
  https://console.developers.google.com/apis/credentials/consent[Google API Console > Credentials > OAuth consent screen].
  Fill in some meaningful values and save.

2.1 Switch to https://console.developers.google.com/apis/credentials[Credentials tab]

2.2 Create credentials > OAuth Client ID > Web application.

2.2.1 Fill in the Name and note it for the `GOOGLE_API_APPLICATION_NAME` environment variable.

2.2.2 Add `https://developers.google.com/oauthplayground` to Authorized redirect URIs.

2.2.3 Note the `Client ID` for the `GOOGLE_API_CLIENT_ID` environment variable
  and `Client secret` for `GOOGLE_API_CLIENT_SECRET`.

2.2.4 Save.

3. Still being logged in to Google as `john-the-tester`, go to https://developers.google.com/oauthplayground/[OAuth 2.0 Playground]

3.1 Click the Gears icon `OAuth 2.0 Configuration` in the top right corner

3.1.1 Make sure `Access type` is `Offline`

3.1.2 Check `Use your own OAuth credentials` and fill in the `Client ID` and `Client secret` you noted in step 2.2.3.

3.1.3 Close the `OAuth 2.0 Configuration` dialog.

3.2 Back in the main OAuth 2.0 Playground pane, on the left in the list of APIs, select `Gmail API v1` > `https://mail.google.com/`

3.3 Click `Authorize APIs`

3.3.1 If Google lets you choose an account, choose the `john-the-tester` account

3.3.2 If Google warns `This app isn't verified`, click `Advanced` and then click `Go to <your_app_name> (unsafe)`

3.3.3 Allow your app to use the selected scope

3.4 Back in the Back in the main OAuth 2.0 Playground pane:

3.4.1 You can ignore the newly created `Authorization code`

3.4.2 Click `Exchange authorization code for tokens`

3.4.3 Previous step brings you to Step 3 of the OAuth 2.0 Playground which is not what we want. Go back to Step 2. of OAuth 2.0 Playground.

3.4.4 Back in the Step 2 of OAuth 2.0 Playground, note the `Refresh token` for the `GOOGLE_API_REFRESH_TOKEN` environment variable.
