Deploying Streamlit-Authenticator via Streamlit Community Cloud

Hi @mkhorasani,

Firstly your component is a great contribution to the Streamlit community and I have enjoyed reading your (recently purchased!) book.

I have been able to successfully get your Streamlit-Authenticator app working locally by having a config.yml setup in my root directory. I use the example structure you have provided in your documentation, replacing the passwords with hashes with your hash encryptor.

However, I am unsure how I specify those same credentials when I go to deploy my app on Streamlit Community Cloud (as a private app) within the Secrets manager. I would rather not have my config.yml file hosted secretly on GitHub and would rather just specify those credentials in Secrets manager.

Can you (or anyone else really :blush:) please help me with the correct specification in Streamlit secrets manager?

My local config.yml file:

credentials:
  usernames:
    JoeBloggs:
      email: joe.bloggs@company.com
      name: Joe Bloggs
      password: #_some_hashed_password_@#@#41
cookie:
  expiry_days: 0.5
  key: some_signature_key
  name: some_cookie_name
preauthorized:
  emails:
  - joe.bloggs@email.com

My current streamlit Secrets manager file (which doesn’t work);

[credentials]
[usernames] = "JoeBloggs"
[email] = "joe.bloggs@company.com"
[name] ="Joe Bloggs"
[password]= "#_some_hashed_password_@#@#41"

[cookie]
[expiry_days]="0.5"
[key]="some_signature_key"
[name]="some_cookie_name"

[preauthorized]
[emails] = "joe.bloggs@email.com"

Thanks in advance for any help given :raised_hand_with_fingers_splayed::raised_hand_with_fingers_splayed::+1:

1 Like

Try this method.

secrets

[cookie]
expiry_days = 1
key = "some_signature_key"
name = "some_cookie_name"

[credentials]
usernames = {dbaldwin = {email = "dbaldwin@gmail.com", name = "David Baldwin", password = "$2b$12$L035ey6vkdHW6523PDg24ezWgKB2mEeI7ARaonKcLoXNOg6wtCGc."}, jsmith = {email = "jsmith@gmail.com", name = "John Smith", password = "$2b$12$L035ey6vkdHW6523PDg24ezWgKB2mEeI7ARaonKcLoXNOg6wtCGc."}}

[preauthorized]
emails = ["256melsby@gmail.com"]

script

authenticator = stauth.Authenticate(
    dict(st.secrets['credentials']),
    st.secrets['cookie']['name'],
    st.secrets['cookie']['key'],
    st.secrets['cookie']['expiry_days'],
    st.secrets['preauthorized']
)
4 Likes

Hey @C_Quang thank you for purchasing our book! I see that this question has already been answered above, so I just wanted to take this opportunity to say thank you.

Hi @ferdy thanks so much for your help - can’t wait to try this! Sorry for late reply :blush:

Hi @mkhorasani sorry for the late reply. I am really eager to try the solution @ferdy posted above. Do you know whether that solution would also work in other secrets management functions for other services .e.g like Render etc.?

BTW - I’m still making my way through your book. Great read and covers some really important material front end and back end.

Hi @ferdy I can confirm your answer works on Streamlit cloud! Thanks very much :raised_hand_with_fingers_splayed::raised_hand_with_fingers_splayed::raised_hand_with_fingers_splayed::raised_hand_with_fingers_splayed::+1::blush:

1 Like

Hey @C_Quang, I’m not sure about other services, but as long as such services can take a dictionary, then I can’t imagine it being a problem. And that’s great to hear that you’re enjoying the book, thank you so much for making the purchase!

1 Like

Would this approach also allow for the implementation of a “register user” functionality? Basically, is there a way to update the secrets as someone registers as a new user? Thanks!

@mkhorasani

I believe so, you would have to update the secrets file each time a new user registers.