Build a SaaS with Streamlit: Google Login and Stripe Subscriptions
The st-paywall package puts a Stripe or Buy Me a Coffee subscription check in front of a Streamlit app with one call, add_auth(), so only logged-in, paying users reach the content. Below: the Google login, the secrets file, the Stripe payment link and deployment to Streamlit Community Cloud.
Install and set up
The project needs the st-paywall package, a main script and a secrets file. I install the package from the terminal, create streamlit_app.py, and add a folder named .streamlit with a secrets.toml file inside it, which holds every key the paywall reads.
pip install st-paywall
The login also needs Authlib (pip install Authlib), which Streamlit uses for st.login(). If you only need a username and password and no payments, a simple Streamlit login form is less setup.
Google login
Users log in with their Google account, so the app needs an OAuth client from the Google Cloud Console. I create a new project there, fill in the consent screen that users see at login, and then create credentials of the type OAuth client ID for a web application.
The client ID and client secret go into an [auth] section of secrets.toml, together with the redirect URI (the app URL followed by /oauth2callback), a random cookie secret and Google’s server metadata URL. The /oauth2callback address must also be listed as an authorized redirect URI on the OAuth client in Google Cloud. The Streamlit documentation for st.login shows the exact section.

The screenshot shows the older 0.1.x settings from the video, where these values sat at the top level of secrets.toml instead of under [auth].
The app code
The app logs the user in first and then calls add_auth(). With required=True, st-paywall stops the script for anyone who is not logged in and subscribed and shows a subscribe button instead. Everything below that line is the paid content.
import streamlit as st
from st_paywall import add_auth
st.set_page_config(layout="wide")
st.title("The Most Fantabulous SaaS Ever! 🚀")
if not st.user.is_logged_in:
if st.button("Log in with Google"):
st.login()
st.stop()
add_auth(required=True)
st.write(f"Subscription Status: {st.session_state.user_subscribed}")
st.write("🎉 Yay! You're all set and subscribed! 🎉")
st.write(f"By the way, your email is: {st.user.email}")
For a subscribed user, st.session_state.user_subscribed is True and the email comes from st.user.email. Until a payment provider is configured, the app shows an error after the login, which is expected at this point.
The video uses st-paywall 0.1.x, where add_auth() added the login button to the sidebar itself and the email sat in session state. That version of the code:
import streamlit as st
from st_paywall import add_auth
st.set_page_config(layout="wide")
st.title("The Most Fantabulous SaaS Ever! 🚀")
add_auth(required=True)
# ONLY AFTER THE AUTHENTICATION + SUBSCRIPTION, THE USER WILL SEE THIS ⤵
# The email and subscription status is stored in session state.
st.write(f"Subscription Status: {st.session_state.user_subscribed}")
st.write("🎉 Yay! You're all set and subscribed! 🎉")
st.write(f'By the way, your email is: {st.session_state.email}')
Stripe payments
st-paywall checks subscriptions against a Stripe payment link, and the link must be for a recurring price: a one-time payment does not work. In Stripe test mode, I create a product named My Cool Service, set a recurring price and create a payment link for it.

The payment link goes into secrets.toml as stripe_link_test (and stripe_link for live mode), with payment_provider = "stripe" and testing_mode = true while you test. The app also needs a Stripe API key: I create a restricted key in the Stripe dashboard with read access to customers and paste it as stripe_api_key_test (or stripe_api_key). In the payment link settings, set the redirect after payment to your app URL so customers land back in the app.

Deploy
I deploy on Streamlit Community Cloud from a GitHub repository. The repository needs a requirements.txt with Streamlit, st-paywall and Authlib, and a .gitignore that keeps secrets.toml out of the upload.
In Community Cloud, I create a new app, select the repository and choose the app URL. After deployment, I paste the contents of my secrets file into the app settings, with the redirect URI changed to the deployed URL and testing_mode set the way I want it. The general deployment steps are also in my Streamlit sales dashboard tutorial.

Later changes are a commit and push to the repository; the deployed app updates automatically.

Buy Me a Coffee
st-paywall supports two payment providers: Stripe and Buy Me a Coffee. Buy Me a Coffee memberships need less setup. The st-paywall documentation lists these lines for the secrets file:
payment_provider = "bmac"
bmac_api_key = "eyJ0...."
bmac_link = "https://www.buymeacoffee.com/..."
If you want to sell a one-off digital product instead of a subscription, see how I build a sales page with Streamlit.
