firestore-cli v1.0.5
Firestore CLI Tool
Setup Instructions
User Guide: How to Obtain OAuth2 Credentials for firestore-cli
firestore-cli
requires a credentials.json
file to authenticate and interact with Google Cloud services. Here's how to obtain this file using the Google Cloud Console and the gcloud
CLI.
1. Obtaining Credentials via Google Cloud Console
Step 1: Access the Google Cloud Console
- Open your browser and go to the Google Cloud Console.
- Sign in with your Google account.
Step 2: Create or Select a Project
- In the top navigation bar, click the project dropdown and select an existing project or create a new one.
- Ensure the Firestore and required APIs are enabled:
- Navigate to "APIs & Services" > "Library".
- Search for and enable the Cloud Firestore API and other APIs your application requires.
Step 3: Create OAuth 2.0 Credentials
- Navigate to "APIs & Services" > "Credentials" in the left-hand menu.
- Click "Create Credentials" and select "OAuth client ID".
- If prompted, configure your OAuth consent screen:
- Enter an application name and other required fields.
- Add
http://localhost
or any custom redirect URIs relevant to your workflow.
- Save the settings and return to credentials creation.
- If prompted, configure your OAuth consent screen:
- Choose "Desktop Application" as the application type.
- Enter a name for the credentials (e.g., "Firestore CLI Credentials").
- Click "Create". A dialog will display your client ID and client secret.
Step 4: Download the credentials.json
File
- Click "Download JSON" to save your credentials as a
credentials.json
file. - Move the file to a secure and accessible location.
- Provide the file path to
firestore-cli
during setup or as a command-line argument.
2. Obtaining Credentials via gcloud
CLI
Prerequisites
- Install the
gcloud
CLI. - Authenticate the
gcloud
CLI by running:gcloud auth login
- Set a default project:
gcloud config set project [PROJECT_ID]
Step 1: Enable Required APIs
Run the following command to enable the Firestore API:
gcloud services enable firestore.googleapis.com
Step 2: Create OAuth 2.0 Client
Use the following command to create OAuth credentials:
gcloud auth application-default login
- Follow the link opened in your browser.
- Sign in and authorize access.
After completing authentication, a default credentials file will be created in your home directory, typically located at:
~/.config/gcloud/application_default_credentials.json
Copy this file to your desired location and rename it
credentials.json
if needed.
3. Providing Credentials to firestore-cli
firestore-cli
requires the path to the credentials.json
file. Provide this path in one of the following ways:
Option 1: CLI Argument
Use the --credentials
or -c
flag to specify the file:
firestore-cli --credentials /path/to/credentials.json
Option 2: Default Location
Place the file in a default directory (e.g., ~/.config/firestore-cli/credentials.json
, or %APP_DATA%\firestore-cli\credentials.json
) to avoid specifying it each time.
User Guide: How to Obtain and Use Service Account Keys for firestore-cli
firestore-cli
supports authentication using service account keys, which are particularly useful for server-to-server interactions with Google Cloud services. Follow this guide to generate and configure your service account key.
1. Obtaining Service Account Keys via Google Cloud Console
Step 1: Access the Google Cloud Console
- Open your browser and navigate to the Google Cloud Console.
- Sign in with your Google account.
Step 2: Create or Select a Project
- Click the project dropdown in the top navigation bar and select an existing project or create a new one.
- Enable the Cloud Firestore API and other required APIs for your project:
- Navigate to "APIs & Services" > "Library".
- Search for "Cloud Firestore API" and click Enable.
Step 3: Create a Service Account
- Go to "IAM & Admin" > "Service Accounts" in the left-hand menu.
- Click "Create Service Account".
- Enter a name for the service account (e.g., "Firestore CLI Service Account").
- (Optional) Add a description.
- Click Create and Continue.
Step 4: Assign a Role
- In the "Grant this service account access to project" step:
- Assign the Cloud Datastore Owner role (or a more restrictive role suitable for your needs, such as Cloud Datastore User).
- Click Continue.
Step 5: Create and Download the Key
- Skip adding users in the "Grant users access to this service account" step and click Done.
- Locate the newly created service account in the list and click the three-dot menu (⋮) on the right.
- Select "Manage Keys" > "Add Key" > "Create New Key".
- Choose JSON as the key type and click Create.
- A JSON file containing your service account key will download automatically.
Step 6: Secure the Key
- Move the downloaded JSON file to a secure and accessible location.
- Treat this file like a password—do not expose it publicly.