mkhorasani / Streamlit-Authenticator

A secure authentication module to validate user credentials in a Streamlit application.
Apache License 2.0
1.38k stars 229 forks source link

Implementing a "register user" fails #39

Closed daytonjones closed 1 year ago

daytonjones commented 1 year ago

I've added a widget to allow user to register (per the doc): try: if authenticator.register_user('Register user', preauthorization=False): st.success('User registered successfully') except Exception as e: st.error(e)

But when loading the app, I get: "Pre-authorization argument must not be None"

streamlit == 1.9.2 streamlit-authenticator == 0.2.1 OS == Ubuntu 16.04 Python == 3.6.13

Screen Shot 2022-11-30 at 6 18 04 PM

mkhorasani commented 1 year ago

Please ensure you are supplying the preauthorization argument when you are initially constructing your authenticator object as follows:


authenticator = stauth.Authenticate(
    config['credentials'],
    config['cookie']['name'], 
    config['cookie']['key'], 
    config['cookie']['expiry_days'],
    config['preauthorized']
)
daytonjones commented 1 year ago

I added the "config['preauthorized']" argument as above, but now when loading the app I get:

KeyError: 'preauthorized'
Traceback:
File "/usr/local/lib/python3.6/site-packages/streamlit/scriptrunner/script_runner.py", line 475, in _run_script
    exec(code, module.__dict__)
File "/home/ubuntu/DROPS/drops.py", line 37, in <module>
    config['preauthorized']

Here is the full section from my app:

import streamlit_authenticator as stauth

with open ('/home/ubuntu/DROPS/.streamlit/auth_config.yaml') as file:
    config = yaml.load(file, Loader=SafeLoader)

authenticator = stauth.Authenticate(
        config['credentials'],
        config['cookie']['name'],
        config['cookie']['key'],
        config['cookie']['expiry_days'],
        config['preauthorized']
)

try:
    if authenticator.register_user('Register User', preauthorization=False):
        st.success('User registered successfully')
except Exception as e:
    st.error(e)
mkhorasani commented 1 year ago

Please make sure that you have an empty preauthorized element in your config file as shown below:


preauthorized:
  emails: []
daytonjones commented 1 year ago

Ah... ok..thanks. Quick (final) question... can the "emails: []" contain a wildcard? I.E. ; "*.my.domain"

mkhorasani commented 1 year ago

Not in its current implementation, but you can just leave it completely empty.