Exploring different ways for Google Authentication in Streamlit
Playing with multiple ways of authenticating through a Google account within Streamlit:
openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365
in WSL2 on Windows.cert.pem
and key.pem
to .streamlit
folder at root of projectsslCertFile = ".streamlit/cert.pem"
and sslKeyFile = ".streamlit/key.pem"
to .streamlit/config.toml
[server]
sslCertFile = ".streamlit/cert.pem"
sslKeyFile = ".streamlit/key.pem"
Better use Caddy or Nginx to SSL proxify Streamlit & FastAPI
Head to GCP Console
In APIs and services > OAuth consent screen:
openid
, ../auth/userinfo.profile
and .../auth/userinfo.email
.
Calendar API
(either by typing it in search bar or from APIs and services >Enabled APIs and Services), add the .../auth/calendar.events.readonly
to ask the user for Calendar authorizationadd tests users in 3rd page
In APIs and services > Credentials, create a OAuth 2.0 Web Client ID and download it as a JSON file client_secret.json
to the root of the project.
https://localhost:8501
http://localhost:9000/
: Flask endpoint from google-oauthlib's InstalledAppFlow.run_local_server
and get_user_credentials
methodshttp://localhost:8000/auth/code
and http://localhost:8000/auth/token
: our own FastAPI callback endpointsclient_id
and client_secret
to .streamlit/secrets.toml
fileclient_id="XXX.apps.googleusercontent.com"
client_secret="XXXXXX-..."
Next, head to Firebase Console
firebase_secret.json
to the root of the project.Add app
button, and add a Web
App. After creation, copy the firebaseConfig
variable into a firebase_client.json
file at the root of the project.Install Python packages: pip install -r requirements.txt
Run Streamlit multipage app: streamlit run streamlit_app.py
https://localhost:8501
For pages 3 and 4, run FastAPI redirect server in parallel: fastapi dev fastapi_server.py
.
http://localhost:8000/docs
. Visualize state of app in /sessions
URI.