You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-28Lines changed: 65 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,18 +22,20 @@
22
22
-[Creating a config file](#3-creating-a-config-file)
23
23
-[Setup](#4-setup)
24
24
-[Creating a login widget](#5-creating-a-login-widget)
25
-
-[Creating a guest login button](#6-creating-a-guest-login-button) 🚀 **NEW**
25
+
-[Creating a guest login widget](#6-creating-a-guest-login-widget) 🚀 **NEW**
26
26
-[Authenticating users](#7-authenticating-users)
27
-
-[Creating a reset password widget](#8-creating-a-reset-password-widget)
28
-
-[Creating a new user registration widget](#9-creating-a-new-user-registration-widget)
29
-
-[Creating a forgot password widget](#10-creating-a-forgot-password-widget)
30
-
-[Creating a forgot username widget](#11-creating-a-forgot-username-widget)
31
-
-[Creating an update user details widget](#12-creating-an-update-user-details-widget)
32
-
-[Updating the config file](#13-updating-the-config-file)
27
+
-[Enabling two factor authentication](#8-enabling-two-factor-authentication) 🚀 **NEW**
28
+
-[Creating a reset password widget](#9-creating-a-reset-password-widget)
29
+
-[Creating a new user registration widget](#10-creating-a-new-user-registration-widget)
30
+
-[Creating a forgot password widget](#11-creating-a-forgot-password-widget)
31
+
-[Creating a forgot username widget](#12-creating-a-forgot-username-widget)
32
+
-[Creating an update user details widget](#13-creating-an-update-user-details-widget)
33
+
-[Updating the config file](#14-updating-the-config-file)
33
34
-[License](#license)
34
35
35
36
### 1. Quickstart
36
37
38
+
* Subscribe to receive a free [API key](https://streamlitauthenticator.com)
37
39
* Check out the [demo app](https://demo-app-v0-3-3.streamlit.app/).
38
40
* Feel free to visit the [API reference](https://streamlit-authenticator.readthedocs.io/en/stable/).
39
41
* And finally follow the tutorial below.
@@ -64,8 +66,8 @@ import streamlit_authenticator as stauth
64
66
```python
65
67
cookie:
66
68
expiry_days: 30
67
-
key: some_signature_key # Must be a string
68
-
name: some_cookie_name
69
+
key: # To be filled with any string
70
+
name: # To be filled with any string
69
71
credentials:
70
72
usernames:
71
73
jsmith:
@@ -101,6 +103,7 @@ oauth2: # Optional
101
103
pre-authorized: # Optional
102
104
emails:
103
105
- melsby@gmail.com
106
+
api_key: # Optional - register to receive a free API key: https://streamlitauthenticator.com
104
107
```
105
108
106
109
*_Please note that the 'failed_login_attempts' and 'logged_in' fields corresponding to each user's number of failed login attempts and log-in status in the credentials will be added and managed automatically._
> - Provides a validator object that will check the validity of the username, name, and email fields.
153
156
> -**auto_hash:**_bool, default True_
154
157
> - Automatic hashing requirement for passwords, True: plain text passwords will be hashed automatically, False: plain text passwords will not be hashed automatically.
158
+
> -**api_key:**_str, optional, default None_
159
+
> - API key used to connect to the cloud server to send reset passwords and two factor authorization codes to the user by email.
155
160
> -****kwargs:**_dict, optional_
156
161
> - Arguments to pass to the Authenticate class.
157
162
@@ -194,7 +199,7 @@ except Exception as e:
194
199
***_Please remember to re-invoke an 'unrendered' login widget on each and every page in a multi-page application._**
195
200
***_Please remember to update the config file (as shown in step 13) after you use this widget._**
196
201
197
-
### 6. Creating a guest login button
202
+
### 6. Creating a guest login widget
198
203
199
204
* You may use the **experimental_guest_login** button to log in non-registered users with their Google or Microsoft accounts using OAuth2.
200
205
* To create the client ID and client secret parameters for Google OAuth2 please refer to [Google's documentation](https://developers.google.com/identity/protocols/oauth2).
@@ -229,6 +234,8 @@ except Exception as e:
229
234
> - Disables the ability for the same user to log in multiple sessions, True: single session allowed, False: multiple sessions allowed.
230
235
> -**roles:**_list, optional, default None_
231
236
> - User roles for guest users.
237
+
> -**use_container_width:**_bool, default False_
238
+
> - Button width setting, True: width will match container, False: width will fit to button contents.
* Please note that upon successful login, the guest user's name, email, and other information will be registered in the credentials dictionary and their re-authentication cookie will be saved automatically.
242
-
***_Please remember to update the config file (as shown in step 13) after you use this button._**
243
249
244
250
### 7. Authenticating users
245
251
246
-
* You can then retrieve the name, authentication status, and username from Streamlit's session state using **st.session_state['name']**, **st.session_state['authentication_status']**, **st.session_state['username']**, and **st.session_state['roles']** to allow a verified user to access restricted content.
252
+
* You can then retrieve the name, authentication status, username, and roles from Streamlit's session state using the keys **'name'**, **'authentication_status'**, **'username'**, and **'roles'** to allow a verified user to access restricted content.
247
253
* You may also render a logout button, or may choose not to render the button if you only need to implement the logout logic programmatically.
248
254
* The optional **key** parameter for the logout button should be used with multi-page applications to prevent Streamlit from throwing duplicate key errors.
* You may also retrieve the number of failed login attempts a user has made by accessing **st.session_state['failed_login_attempts']** which returns a dictionary with the username as key and the number of failed attempts as the value.
286
+
* You may also retrieve the number of failed login attempts a user has made by accessing **st.session_state.get('failed_login_attempts')** which returns a dictionary with the username as key and the number of failed attempts as the value.
279
287
280
-
### 8. Creating a reset password widget
288
+
### 8. Enabling two factor authentication
289
+
290
+
* You may enable two factor authentication for the **register_user**, **forgot_password**, and **forgot_username** widgets for enhanced security.
291
+
* First register to receive a free API key [here](https://streamlitauthenticator.com).
292
+
* Then add your API key to the the authenticator object as **api_key** or alternatively add it to the config file as shown in step 3.
293
+
* Finally set the **two_factor_auth** parameter for the widget to True, this will prompt the user to enter a four digit code sent to their email.
* For the **forgot_password** and **forgot_username** widgets if you require the returned password and username to be sent to the user's email then you may set the **send_email** parameter to True.
* You may use the **reset_password** widget to allow a logged in user to modify their password as shown below.
283
308
284
309
```python
285
-
if st.session_state['authentication_status']:
310
+
if st.session_state.get('authentication_status'):
286
311
try:
287
-
if authenticator.reset_password(st.session_state['username']):
312
+
if authenticator.reset_password(st.session_state.get('username')):
288
313
st.success('Password modified successfully')
289
314
exceptExceptionas e:
290
315
st.error(e)
@@ -312,7 +337,7 @@ if st.session_state['authentication_status']:
312
337
313
338
***_Please remember to update the config file (as shown in step 13) after you use this widget._**
314
339
315
-
### 9. Creating a new user registration widget
340
+
### 10. Creating a new user registration widget
316
341
317
342
* You may use the **register_user** widget to allow a user to sign up to your application as shown below.
318
343
* If you require the user to be pre-authorized, define a **pre_authorized** list of emails that are allowed to register, and add it to the config file or provide it as a parameter to the **register_user** widget.
@@ -346,6 +371,10 @@ except Exception as e:
346
371
> - User roles for registered users.
347
372
> -**merge_username_email:**_bool, default False_
348
373
> - Merges username into email field, True: username will be the same as the email, False: username and email will be independent.
374
+
> -**password_hint:**_bool, default True_
375
+
> - Requirement for entering a password hint, True: password hint field added, False: password hint field removed.
376
+
> -**two_factor_auth:**_bool, default False_
377
+
> - Specifies whether to enable two factor authentication for the forgot password widget, True: two factor authentication enabled, False: two factor authentication disabled.
349
378
> -**clear_on_submit:**_bool, default False_
350
379
> - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.
351
380
> -**key:**_str, default 'Register user'_
@@ -364,7 +393,7 @@ except Exception as e:
364
393
365
394
***_Please remember to update the config file (as shown in step 13) after you use this widget._**
366
395
367
-
### 10. Creating a forgot password widget
396
+
### 11. Creating a forgot password widget
368
397
369
398
* You may use the **forgot_password** widget to allow a user to generate a new random password.
370
399
* The new password will be automatically hashed and saved in the credentials dictionary.
@@ -392,6 +421,10 @@ except Exception as e:
392
421
> - Customizes the text of headers, buttons and other fields.
393
422
> -**captcha:**_bool, default False_
394
423
> - Specifies the captcha requirement for the forgot password widget, True: captcha required, False: captcha removed.
424
+
> -**send_email:**_bool, default False_
425
+
> - Specifies whether to send the generated password to the user's email, True: password will be sent to user's email, False: password will not be sent to user's email.
426
+
> -**two_factor_auth:**_bool, default False_
427
+
> - Specifies whether to enable two factor authentication for the forgot password widget, True: two factor authentication enabled, False: two factor authentication disabled.
395
428
> -**clear_on_submit:**_bool, default False_
396
429
> - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.
397
430
> -**key:**_str, default 'Forgot password'_
@@ -410,7 +443,7 @@ except Exception as e:
410
443
411
444
***_Please remember to update the config file (as shown in step 13) after you use this widget._**
412
445
413
-
### 11. Creating a forgot username widget
446
+
### 12. Creating a forgot username widget
414
447
415
448
* You may use the **forgot_username** widget to allow a user to retrieve their forgotten username.
416
449
* The widget will return the username and email which the developer should then transfer to the user securely.
@@ -436,6 +469,10 @@ except Exception as e:
436
469
> - Customizes the text of headers, buttons and other fields.
437
470
> -**captcha:**_bool, default False_
438
471
> - Specifies the captcha requirement for the forgot username widget, True: captcha required, False: captcha removed.
472
+
> -**send_email:**_bool, default False_
473
+
> - Specifies whether to send the retrieved username to the user's email, True: username will be sent to user's email, False: username will not be sent to user's email.
474
+
> -**two_factor_auth:**_bool, default False_
475
+
> - Specifies whether to enable two factor authentication for the forgot username widget, True: two factor authentication enabled, False: two factor authentication disabled.
439
476
> -**clear_on_submit:**_bool, default False_
440
477
> - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.
0 commit comments