how to add firebase service account key on railway and handle in python code

suraj-bhatt1217
HOBBY

2 months ago

how to add firebase service account key on railway and handle in python code

$10 Bounty

3 Replies

2 months ago

Step 1

  • In the Firebase console, navigate to your project's settings by clicking the gear icon next to "Project Overview."

  • Select Project settings, then go to the Service accounts tab

  • Click the Generate new private key button. A confirmation pop-up will appear

  • Click Generate Key to download a JSON file containing your service account credentials

  • Store this JSON file securely and do not commit it to a public code repository, as it provides administrative access to your Firebase project

Step 2

  • Open your project in the Railway dashboard and navigate to the service where you want to add the key, the one hosting the python code.

  • Go to the Variables tab.

  • Click on New Variable. It is recommended to add the key via the Raw Editor to ensure correct formatting.

  • Create a variable named FIREBASE_CREDENTIALS_JSON.

  • Open the JSON file you downloaded from Firebase, copy its entire content, and paste it as the value for the FIREBASE_CREDENTIALS_JSON variable

Step 3

Use it! You might need to adjust the dependencies you import according to your use case

import os
import json

# Retrieve the JSON credentials from the environment variable
firebase_creds_json_str = os.environ.get('FIREBASE_CREDENTIALS_JSON')

alexwebgr

Step 1In the Firebase console, navigate to your project's settings by clicking the gear icon next to "Project Overview."Select Project settings, then go to the Service accounts tabClick the Generate new private key button. A confirmation pop-up will appearClick Generate Key to download a JSON file containing your service account credentialsStore this JSON file securely and do not commit it to a public code repository, as it provides administrative access to your Firebase projectStep 2Open your project in the Railway dashboard and navigate to the service where you want to add the key, the one hosting the python code.Go to the Variables tab.Click on New Variable. It is recommended to add the key via the Raw Editor to ensure correct formatting.Create a variable named FIREBASE_CREDENTIALS_JSON.Open the JSON file you downloaded from Firebase, copy its entire content, and paste it as the value for the FIREBASE_CREDENTIALS_JSON variableStep 3Use it! You might need to adjust the dependencies you import according to your use caseimport os import json # Retrieve the JSON credentials from the environment variable firebase_creds_json_str = os.environ.get('FIREBASE_CREDENTIALS_JSON')

sim
FREE

2 months ago

This is a very detailed reply and it will help you. I do not wan to take the bounty but here is the documentation for environment variables https://docs.railway.com/guides/variables#using-variables-in-your-services


sim
FREE

2 months ago