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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.