Hello,
I may have a question on how to deploy an app on the community server that requires a firebase user authentication, in relation to passing API Keys, etc. through secrets.toml.
I really like this feature, it’s super useful.
For a firebase authentication, one needs to do the following, i.e pass an entire json file:
However, as far as I know, we can only use variables in the settings during the app deployment.
What I’m doing for now is to copy all the fields needed in my_project_settings.json in the secrets.toml file then make a dictionary from these variables as input for the Certificate method.
It’s working but I’m wondering if there’s a better way to do that.
Thanks in advance.
Regards,
Jonathan
ps: I’ve been using streamlit since only a month now and I really like it.
Hi there!
Streamlit requires secrets to be in the TOML format. This does not allow the normal usage of JSON files as a dictionary. However, in order to directly create a dictionary, you can format your JSON data to be TOML compatible. In case of firebase credentials, it can be something like this:
As far as I know, it has to be in a single line and use = to separate key-value pairs instead of :.
After copying your JSON, doing a find and replace for the following should work:
Find ,\n, replace all with ,
Find : replace all with =
You can then access it in your project directly as a dictionary.
import streamlit as st
fb_credentials = st.secrets["firebase"]['my_project_settings'] // returns a dictionary
Here’s a great discussion about dictionary variables in the secrets file:
When I used your solution, the fb_credentials type was actually casted as <class 'streamlit.runtime.secrets.AttrDict'>, not a python dict as firebase expects.
so I simply re-casted it as a dictionary and it worked fine now.