Authenticate to Firestore  |  Google Cloud (2024)

This document describes how to authenticate to Firestore programmatically. How you authenticate to Firestore depends on the interface you use to access the API and the environment where your code is running.

The information on this page applies when you use server client librariesand the REST and RPC APIs. If you are using client libraries for mobile orweb clients, authentication is managed by a combination of Firestoresecurity rules and Firebase Auth. For more information, seeSecure data for mobile and web clients.

For more information about Google Cloud authentication, see the authentication overview.

API access

Firestore supports programmatic access. You can access the API in the following ways:

  • Client libraries
  • Google Cloud CLI

Client libraries

The Firestore client libraries provide high-level language support for authenticating to Firestore programmatically. To authenticate calls to Google Cloud APIs, client libraries supportApplication Default Credentials (ADC);the libraries look for credentials in a set of defined locations and use those credentialsto authenticate requests to the API. With ADC, you can makecredentials available to your application in a variety of environments, such as localdevelopment or production, without needing to modify your application code.

Google Cloud CLI

When you use the gcloud CLI to access Firestore, you log in to the gcloud CLI with a user account, which provides the credentials used by the gcloud CLI commands.

If your organization's security policies prevent user accounts from having the required permissions, you can use service account impersonation.

For more information, see Authenticate for using the gcloud CLI. For more information about using the gcloud CLI with Firestore, see the gcloud CLI reference pages.

Set up authentication for Firestore

How you set up authentication depends on the environment where your code is running.

The following options for setting up authentication are the most commonly used. For more options and information about authentication, see Authentication methods.

For a local development environment

You can set up credentials for a local development environment in the following ways:

  • User credentials for client libraries or third-party tools

Client libraries or third-party tools

Set up Application Default Credentials (ADC) in your local environment:

  1. Install the Google Cloud CLI, then initialize it by running the following command:

    gcloud init
  2. If you're using a local shell, then create local authentication credentials for your user account:

    gcloud auth application-default login

    You don't need to do this if you're using Cloud Shell.

    A sign-in screen appears. After you sign in, your credentials are stored in the local credential file used by ADC.

For more information about working with ADC in a local environment, see Local development environment.

On Google Cloud

To authenticate a workload running on Google Cloud, you use the credentials of the service account attached to the compute resource where your code is running, such as a Compute Engine virtual machine (VM) instance. This approach is the preferred authentication method for code running on a Google Cloud compute resource.

For most services, you must attach the service account when you create the resource that will run your code; you cannot add or replace the service account later. Compute Engine is an exception—it lets you attach a service account to a VM instance at any time.

Use the gcloud CLI to create a service account and attach it to your resource:

  1. Install the Google Cloud CLI, then initialize it by running the following command:

    gcloud init
  2. Set up authentication:

    1. Create the service account:

      gcloud iam service-accounts create SERVICE_ACCOUNT_NAME

      Replace SERVICE_ACCOUNT_NAME with a name for the service account.

    2. To provide access to your project and your resources, grant a role to the service account:

      gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" --role=ROLE

      Replace the following:

      • SERVICE_ACCOUNT_NAME: the name of the service account
      • PROJECT_ID: the project ID where you created the service account
      • ROLE: the role to grant
    3. To grant another role to the service account, run the command as you did in the previous step.
    4. Grant the required role to the principal that will attach the service account to other resources.

      gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com --member="user:USER_EMAIL" --role=roles/iam.serviceAccountUser

      Replace the following:

      • SERVICE_ACCOUNT_NAME: the name of the service account
      • PROJECT_ID: the project ID where you created the service account
      • USER_EMAIL: the email address for a Google Account
  3. Create the resource that will run your code, and attach the service account to that resource. For example, if you use Compute Engine:

    Create a Compute Engine instance. Configure the instance as follows:
    • Replace INSTANCE_NAME with your preferred instance name.
    • Set the --zone flag to the zone in which you want to create your instance.
    • Set the --service-account flag to the email address for the service account that you created.
    gcloud compute instances create INSTANCE_NAME --zone=ZONE --service-account=SERVICE_ACCOUNT_EMAIL

For more information about authenticating to Google APIs, see Authentication methods.

On-premises or on a different cloud provider

The preferred method to set up authentication from outside of Google Cloud is to use workload identity federation. For more information, see On-premises or another cloud provider in the authentication documentation.

Access control for Firestore

After you authenticate to Firestore, you must be authorized to access Google Cloud resources. Firestore uses Identity and Access Management (IAM) for authorization.

For more information about the roles for Firestore, see Security for server client libraries. For more information about IAM and authorization, see IAM overview.

What's next

  • Learn about Google Cloud authentication methods.
  • See a list of authentication use cases.
Authenticate to Firestore  |  Google Cloud (2024)
Top Articles
Understanding Cookie Hijacking: How Hackers Can Steal Your Data Without You Knowing
Meet the richest people in the world according to Forbes
Bild Poster Ikea
Avonlea Havanese
Usborne Links
Apex Rank Leaderboard
Gameplay Clarkston
CHESAPEAKE WV :: Topix, Craigslist Replacement
World of White Sturgeon Caviar: Origins, Taste & Culinary Uses
W303 Tarkov
Goldsboro Daily News Obituaries
What Is A Good Estimate For 380 Of 60
Sarpian Cat
Kinkos Whittier
Jvid Rina Sauce
Used Drum Kits Ebay
7 Fly Traps For Effective Pest Control
boohoo group plc Stock (BOO) - Quote London S.E.- MarketScreener
Uktulut Pier Ritual Site
Las 12 mejores subastas de carros en Los Ángeles, California - Gossip Vehiculos
Hanger Clinic/Billpay
Dover Nh Power Outage
Heart Ring Worth Aj
Brazos Valley Busted Newspaper
Parc Soleil Drowning
Gran Turismo Showtimes Near Marcus Renaissance Cinema
Www Va Lottery Com Result
Temu Seat Covers
3 Ways to Drive Employee Engagement with Recognition Programs | UKG
Taylored Services Hardeeville Sc
Rainfall Map Oklahoma
031515 828
Package Store Open Near Me Open Now
Newsday Brains Only
AsROck Q1900B ITX und Ramverträglichkeit
Craigslist Georgia Homes For Sale By Owner
Finland’s Satanic Warmaster’s Werwolf Discusses His Projects
Fapello.clm
Thelemagick Library - The New Comment to Liber AL vel Legis
Complete List of Orange County Cities + Map (2024) — Orange County Insiders | Tips for locals & visitors
Oppenheimer Showtimes Near B&B Theatres Liberty Cinema 12
Avance Primary Care Morrisville
Ehome America Coupon Code
Hanco*ck County Ms Busted Newspaper
Makes A Successful Catch Maybe Crossword Clue
Deezy Jamaican Food
UWPD investigating sharing of 'sensitive' photos, video of Wisconsin volleyball team
Sacramentocraiglist
Costner-Maloy Funeral Home Obituaries
Prologistix Ein Number
Turning Obsidian into My Perfect Writing App – The Sweet Setup
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 6399

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.