Streamlit-Authenticator icon indicating copy to clipboard operation
Streamlit-Authenticator copied to clipboard

form key values when forms are rendered with authenticator

Open PMaye opened this issue 1 year ago • 7 comments

Hi, I really appreciate the multiple options provided for signing in with numerous scenarios thought out. However, I am wondering where to put/assign form key values when using multiple authenticator options authenticator.forgot_password() authenticator.login() authenticator.reset_password()

my exact error message is: There are multiple identical forms with key='Forgot password'.

none of these accept key values to provide different ids for different forms? unlike a normal st.form() which does allow a key value

where can i specify this? thanks Peter

PMaye avatar Feb 09 '24 20:02 PMaye

very helpful link to problem solve this library: https://stackoverflow.com/questions/73152424/streamlit-authenticate-init-got-multiple-values-for-argument-cookie-expir/73179301#73179301?newreg=c8011459a6eb4000ae5aafc12b90f1ca

PMaye avatar Feb 12 '24 18:02 PMaye

@pmaye

However, I am wondering where to put/assign form key values when using multiple authenticator options authenticator.forgot_password() authenticator.login() authenticator.reset_password()

In the current source code, forgot_password() uses a key of "Forgot password", "Login" for longin() and "Reset password" for reset_password().

Form keys are not settable at present.

I have a branch from a fork where users can specify the form parameters as well as the authenticator parameters. If key is not specified the default key "Forgot password" will be used.

sample

    # Creating a forgot password widget
    try:
        username_of_forgotten_password, email_of_forgotten_password, new_random_password = \
            authenticator.forgot_password(
                'form_key_1',
                location='main',
                fields={'Form name': 'Forgot password with form key 1'},
                clear_on_submit=True
            )
        if username_of_forgotten_password:
            st.success('New password sent securely')
            # Random password to be transferred to the user securely
        elif username_of_forgotten_password == False:
            st.error('Username not found')
    except Exception as e:
        st.error(e)

    # Creating a forgot password widget
    try:
        username_of_forgotten_password, email_of_forgotten_password, new_random_password = \
            authenticator.forgot_password(clear_on_submit=True)
        if username_of_forgotten_password:
            st.success('New password sent securely')
            # Random password to be transferred to the user securely
        elif username_of_forgotten_password == False:
            st.error('Username not found')
    except Exception as e:
        st.error(e)

So far this is only implemented in Forgot password.

How to test

  • Create requirements.txt and add the libs

requirements.txt

streamlit==1.32.0
git+https://github.com/fsmosca/Streamlit-Authenticator.git@add-forgotpassword-key
  • Install the requirements with pip install -r requirements.txt

Test result on double forgot password

image

fsmosca avatar Mar 12 '24 13:03 fsmosca

Revised the login() on that branch. Now form key and other form parameter are supported.

Example

authenticator.login(
    'myformkey',
    clear_on_submit=True,
    location='main',
    fields={'Form name':'Login1', 'Username': 'Username1', 'Password':'Password1', 'Login':'Login1'}',
    max_concurrent_users=10
)

fsmosca avatar Mar 13 '24 02:03 fsmosca

Hi @pmaye, currently, all the widgets/forms by default have unique keys. If you wish to use multiples of the same widget then yes that would be an issue. Is that what you are trying to do?

mkhorasani avatar Mar 26 '24 20:03 mkhorasani

*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi Mohammad thanks for getting back to me on this. I think I have resolved this problem. However, now I am struggling with simply running streamlit as a localhost on my computer. Something is blocking it and I cannot figure out what. Any suggestions would be appreciated. thanks

Peter Maye, PhD | Associate Professor Department of Reconstructive Sciences Center for Regenerative Medicine University of Connecticut Health Center phone: 860-679-7347 From: Mohammad Khorasani @.> Sent: Tuesday, March 26, 2024 4:02 PM To: mkhorasani/Streamlit-Authenticator @.> Cc: Maye,Peter @.>; Mention @.> Subject: Re: [mkhorasani/Streamlit-Authenticator] form key values when forms are rendered with authenticator (Issue #132)

*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

Hi @pmayehttps://urldefense.com/v3/__https:/github.com/pmaye__;!!Cn_UX_p3!gQVGqlBUwzXD2QnrKzn0JncKsIVa3JuGfuTcEINTxXDtYg0kfPQOrKwgOj35ptK8Bt6D1kkye81lNE5gSbgxcGU$, currently, all the widgets/forms by default have unique keys. If you wish to use multiples of the same widget then yes that would be an issue. Is that what you are trying to do?

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/mkhorasani/Streamlit-Authenticator/issues/132*issuecomment-2021357370__;Iw!!Cn_UX_p3!gQVGqlBUwzXD2QnrKzn0JncKsIVa3JuGfuTcEINTxXDtYg0kfPQOrKwgOj35ptK8Bt6D1kkye81lNE5gXsuI4NA$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AI632LWKXM4BP5MKO7MYCFLY2HH3PAVCNFSM6AAAAABDCB5NG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRRGM2TOMZXGA__;!!Cn_UX_p3!gQVGqlBUwzXD2QnrKzn0JncKsIVa3JuGfuTcEINTxXDtYg0kfPQOrKwgOj35ptK8Bt6D1kkye81lNE5gxWVLbXY$. You are receiving this because you were mentioned.Message ID: @.@.>>

PMaye avatar Mar 26 '24 20:03 PMaye

*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi Mohammad thanks for getting back to me on this. I think I have resolved this problem. However, now I am struggling with simply running streamlit as a localhost on my computer. Something is blocking it and I cannot figure out what. Any suggestions would be appreciated. thanks Peter Maye, PhD | Associate Professor Department of Reconstructive Sciences Center for Regenerative Medicine University of Connecticut Health Center phone: 860-679-7347 From: Mohammad Khorasani @.> Sent: Tuesday, March 26, 2024 4:02 PM To: mkhorasani/Streamlit-Authenticator @.> Cc: Maye,Peter @.>; Mention @.> Subject: Re: [mkhorasani/Streamlit-Authenticator] form key values when forms are rendered with authenticator (Issue #132) *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi @pmayehttps://urldefense.com/v3/__https:/github.com/pmaye__;!!Cn_UX_p3!gQVGqlBUwzXD2QnrKzn0JncKsIVa3JuGfuTcEINTxXDtYg0kfPQOrKwgOj35ptK8Bt6D1kkye81lNE5gSbgxcGU$, currently, all the widgets/forms by default have unique keys. If you wish to use multiples of the same widget then yes that would be an issue. Is that what you are trying to do? — Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/mkhorasani/Streamlit-Authenticator/issues/132*issuecomment-2021357370__;Iw!!Cn_UX_p3!gQVGqlBUwzXD2QnrKzn0JncKsIVa3JuGfuTcEINTxXDtYg0kfPQOrKwgOj35ptK8Bt6D1kkye81lNE5gXsuI4NA$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AI632LWKXM4BP5MKO7MYCFLY2HH3PAVCNFSM6AAAAABDCB5NG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRRGM2TOMZXGA__;!!Cn_UX_p3!gQVGqlBUwzXD2QnrKzn0JncKsIVa3JuGfuTcEINTxXDtYg0kfPQOrKwgOj35ptK8Bt6D1kkye81lNE5gxWVLbXY$. You are receiving this because you were mentioned.Message ID: @.@.>>

Sure, can you please provide more details/screenshots?

mkhorasani avatar Mar 26 '24 20:03 mkhorasani

*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** @.*** @.***

Peter Maye, PhD | Associate Professor Department of Reconstructive Sciences Center for Regenerative Medicine University of Connecticut Health Center phone: 860-679-7347 From: Mohammad Khorasani @.> Sent: Tuesday, March 26, 2024 4:16 PM To: mkhorasani/Streamlit-Authenticator @.> Cc: Maye,Peter @.>; Mention @.> Subject: Re: [mkhorasani/Streamlit-Authenticator] form key values when forms are rendered with authenticator (Issue #132)

*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi Mohammad thanks for getting back to me on this. I think I have resolved this problem. However, now I am struggling with simply running streamlit as a localhost on my computer. Something is blocking it and I cannot figure out what. Any suggestions would be appreciated. thanks Peter Maye, PhD | Associate Professor Department of Reconstructive Sciences Center for Regenerative Medicine University of Connecticut Health Center phone: 860-679-7347 From: Mohammad Khorasani @.> Sent: Tuesday, March 26, 2024 4:02 PM To: mkhorasani/Streamlit-Authenticator @.> Cc: Maye,Peter @.>; Mention @.> Subject: Re: [mkhorasani/Streamlit-Authenticator] form key values when forms are rendered with authenticator (Issue #132https://urldefense.com/v3/__https:/github.com/mkhorasani/Streamlit-Authenticator/issues/132__;!!Cn_UX_p3!gHnhb8PTc18wttJFAqnI745qGnGc8ces2QN2TlCZSO6yYGz86TiPYKOQ-opD6Z6-bGTiQssRirxs9HjNQVyfJus$) *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi @pmayehttps://urldefense.com/v3/__https:/github.com/pmaye__;!!Cn_UX_p3!gHnhb8PTc18wttJFAqnI745qGnGc8ces2QN2TlCZSO6yYGz86TiPYKOQ-opD6Z6-bGTiQssRirxs9HjN4PRtwy0$https://urldefense.com/v3/https:/github.com/pmaye;!!Cn_UX_p3!gQVGqlBUwzXD2QnrKzn0JncKsIVa3JuGfuTcEINTxXDtYg0kfPQOrKwgOj35ptK8Bt6D1kkye81lNE5gSbgxcGU$, currently, all the widgets/forms by default have unique keys. If you wish to use multiples of the same widget then yes that would be an issue. Is that what you are trying to do? — Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/https:/github.com/mkhorasani/Streamlit-Authenticator/issues/132*issuecomment-2021357370;Iw!!Cn_UX_p3!gQVGqlBUwzXD2QnrKzn0JncKsIVa3JuGfuTcEINTxXDtYg0kfPQOrKwgOj35ptK8Bt6D1kkye81lNE5gXsuI4NA$, or unsubscribehttps://urldefense.com/v3/https:/github.com/notifications/unsubscribe-auth/AI632LWKXM4BP5MKO7MYCFLY2HH3PAVCNFSM6AAAAABDCB5NG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRRGM2TOMZXGA;!!Cn_UX_p3!gQVGqlBUwzXD2QnrKzn0JncKsIVa3JuGfuTcEINTxXDtYg0kfPQOrKwgOj35ptK8Bt6D1kkye81lNE5gxWVLbXY$. You are receiving this because you were mentioned.Message ID: @.@.>>

Sure, can you please provide more details/screenshots?

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/mkhorasani/Streamlit-Authenticator/issues/132*issuecomment-2021382938__;Iw!!Cn_UX_p3!gHnhb8PTc18wttJFAqnI745qGnGc8ces2QN2TlCZSO6yYGz86TiPYKOQ-opD6Z6-bGTiQssRirxs9HjNV_lWWx8$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AI632LVRWP5E5YXL6RCSUM3Y2HJQVAVCNFSM6AAAAABDCB5NG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRRGM4DEOJTHA__;!!Cn_UX_p3!gHnhb8PTc18wttJFAqnI745qGnGc8ces2QN2TlCZSO6yYGz86TiPYKOQ-opD6Z6-bGTiQssRirxs9HjNiYimOIw$. You are receiving this because you were mentioned.Message ID: @.@.>>

PMaye avatar Mar 26 '24 20:03 PMaye

Fixed! Please refer to v0.3.3. Customizable keys may now be added to every widget.

mkhorasani avatar Jul 27 '24 14:07 mkhorasani