Google Cloud Project

Setting up credentials with Google Cloud

Setup OAuth2 Credentials in Google Cloud Project

This guide will walk you through the process of setting up OAuth2 credentials for your Google Cloud project.

Step 1: Create a New Service Account


To create a new service account, follow these steps:

  1. Go to the Google Cloud Console.
  2. Create a new project or select the existing one from the dropdown menu.
  3. Navigate to IAM & Admin > Service accounts.
  4. Click on Create Service Account.
  5. Enter a name for your service account and click on Create.

Step 2: Generate a Private Key for Your Service Account


To generate a private key for your service account, follow these steps:

  1. Go to the IAM & Admin > Service accounts page.
  2. Find your newly created service account and click on the three vertical dots next to it.
  3. Click on Create key.
  4. Select JSON (key file) as the key type.
  5. Download the private key file.

Step 3: Create Credentials for Your OAuth2 Client


To create credentials for your OAuth2 client, follow these steps:

  1. Go to the IAM & Admin > Service accounts page.
  2. Find your service account and click on the three vertical dots next to it.
  3. Click on Create key.
  4. Select OAuth client ID as the key type.
  5. Choose Web application or Desktop application, depending on your use case.
  6. Enter a authorized JavaScript origins (e.g., https://yourdomain.com) and authorized redirect URIs (e.g., https://yourdomain.com/callback).
  7. Click on Create.

Step 4: Use Your OAuth2 Credentials


You can now use your OAuth2 credentials to authenticate with Google Cloud services. For example, you can use the google-auth-library library in Python to authenticate:

import os
from google.oauth2 import service_account

# Load your private key file
credentials = service_account.Credentials.from_service_account_file(
    '<private-key-file>',
    scopes=['https://www.googleapis.com/auth/cloud-platform']
)

# Use the credentials to make API requests
client = googleapiclient.discovery.build('cloudresourcemanager', 'v1', credentials=credentials)

Remember to replace <service-account-name>, <private-key-file>, and <service-account-email> with your actual values.