How to get Google OAuth credentials for BigQuery

Applies to Write-Back Server and Write-Back Cloud

 

Summary

This guide will explain how to get your Google OAuth credentials.
You will be guided through all the steps to configure your BigQuery project to get the required data to authenticate on BigQuery.

Guide

You have two options to authenticate on your BigQuery account :

  • Access Token

  • Service Account

Access Token

When configuring your BigQuery project, if your project has status “Testing“ and is configured for external users, the generated access tokens will have the validity of 7 days.

To get your Access and Refresh Tokens you will need to get your Client and Secret Id.

To get the Access Token and Refresh token, we need to:

  1. Create an OAuth ClientID to get ClientID and Client Secret.

  2. Send an Authorization request to Google to get the Authorization Code.

  3. Exchange the Authorization Code to get the Access Token and Refresh Token by sending a Token request to Google.

  4. To simplify the previous 2 steps, we will use Google OAuth 2 Playgound.

Register OAuth ClientID

  1. To Register a new OAuth ClientID, go to Google Developer Console and login.

  2. Go to the tab OAuth Consent Screen, and fill in the details for your OAuth Client:

    1. Application Name: Your Application Name

    2. Support Email: Your Email/ Support Email

    3. Scopes for Google APIs:
      Add Scope -> BigQuery API ../auth/bigquery

    4. Authorized Domains: Any public facing website

    5. Application HomePage: Any public facing website

    6. Application Privacy Policy Link: Your Privacy policy

    7. Below is an example of the consent screen for your reference –

 

3. Click on Save.

4. Go to Credentials tab, click on Create Credentials, and choose OAuth Client ID.

5. Now we should see a screen like below asking for our application type. Choose Web application, provide a name, and click Create.

 

6. We should now see a new popup with our ClientID and Client Secret. Save them, we will need them later.

Get Access and Refresh Tokens

  1. Access Google OAuth Playground here: https://developers.google.com/oauthplayground/

  2. Make sure you enable “Use your own OAtuh credentials“ checkbox and type your ClientId and ClientSecret

  3. Select the following scopes and click on “Authorize APIs“ button.

  4. Enable both permissions and click “Continue“

  5. Click on “Exchange authorization code for tokens“ button.

  6. You will receive and Access and Refresh Token



Service Account

To configure a Service Account you need to:

  • Create a Service Account

  • Get the private key file

Create a Service Account

  1. Go to Credentials tab, click on Create Credentials and choose Service Account.

     

  2. Define a Project name and a Project Id.

  3. Click Create and Continue.

  4. Define the role to this Service Account. Choose BigQuery Admin.

  5. Click continue.

  6. Define the users to have access to this Service Account.

  7. Click Done

Get your private key file

 

  1. Select the account you just created.

  2. Click on Keys tab.

  3. Click Add Key. Add select Create new Key option.

  4. Select JSON format.

  5. Click create.

Currently, only json format is supported.