thisbejim / Pyrebase

A simple python wrapper for the Firebase API.
2.05k stars 525 forks source link

[update] if don't have a apiKey, get the key from serviceAccount.json #441

Open gabriel-batistuta opened 1 year ago

gabriel-batistuta commented 1 year ago

this code allow get the private_key from serviceAccount.json if don't have a apiKey

hello, as it says in issue #98, a user could authenticate with just the serviceAccount.json file, so I made this small change in the code so that if you don't have an api key in config then look in the file serviceAccount.json the api key

changes:

class Firebase:
    """ Firebase Interface """
    def __init__(self, config):
        if config.get("apiKey"):
            self.api_key = config["apiKey"]
        else:
            with open(config["serviceAccount"],'r') as file:
                data = file.read()
                self.api_key = json.loads(data)["private_key"]