Skip to main content

Streamlit RSA Authenticator UI

Project description

Welcome to Streamlit RSA Authenticator UI 🔐

PyPI Download GitHub GitHub license GitHub issues GitHub pull requests

Encryption on Authenticate widget data from client to server.

What is Streamlit RSA Authenticator UI?

What is Http protocol

Http is the information transfer protocol between networked devices. However, all the requests and responses are in plaintext, which means that anyone can read them.

If you want to deploy streamlit server using http protocol (not https protocol) and you add the user authentication, user password can be read by anyone in the network as it is the plaintext for http protocol.

streamlit-rsa-auth-ui correct it by encrypting user information including password at the client browser before transmit to streamlit server using RSA algorithm

What is RSA algorithm

It is asymmetric cryptography, uses two different but mathematically linked keys

Installation

Open a terminal and run:

pip install streamlit-rsa-auth-ui

Quickstart

Gnerate RSA Key Pair

Create a new file generateKeys.py

from streamlit_rsa_auth_ui import Encryptor

encryptor = Encryptor.generateNew(2048)
encryptor.save('rsa', 'authkey')

Run generateKeys.py python script

python generateKeys.py

this will create a private key and public key pair

  • private key with the file name authkey
  • public key with the file name authkey.pub
├── rsa
│ ├── authkey
│ │ authkey.pub

Create streamlit page

Create a new file example.py

import streamlit as st
from streamlit_rsa_auth_ui import Encryptor, authUI, SigninEvent, SigninFormConfig, getEvent
ss = st.session_state

encryptor = Encryptor.load('rsa', 'authkey')
ui = authUI('login_ui_result', encryptor.publicKeyPem)

def checkAuth(username: str, password: str):
    return username == 'test' and password == 'New.Prog'

def login():
    if 'event' in ss and type(ss.event) is SigninEvent: return True
    result = ui.signinForm(default={'remember': True}, configs=SigninFormConfig(remember="Rememeber Me"))
    if result is None: return None

    _dict = encryptor.decrypt(result)
    event = getEvent(_dict)
    if type(event) is not SigninEvent or not checkAuth(event.username, event.password): return False
    ss['event'] = event
    st.rerun()

def logout():
    result = ui.signoutForm()
    if result is None: return False
    _dict = encryptor.decrypt(result)
    event = getEvent(_dict)
    ss['event'] = event
    return True

if not login(): st.stop()
with st.sidebar:
    if logout(): st.rerun()

st.title('Streamlit Rsa Auth UI Test')
button = st.button('test')
button

Run the streamlit app

streamlit run example.py

Change Log

Version 0.0.1

  • Initial release

Version 0.0.2

  • Fix missing frontend issue

Version 0.0.3

  • Optional 'cancel' button to signoutform
  • Minor bug fixed
  • Remove bootstrap.min.css warning

Version 0.0.4

  • Remove location setting(seem redundunt as if you want to add to any container/sidebar you can call with syntax)
  • Add in classname to frontend so that easier to add in custom styling if needed
  • Remove off the unnecessary excess height of streamlit

Version 1.0.0

  • More customizable UI
  • Add inline mode
  • Add ChangePassword UI

Version 1.1.0

  • Add id property in event if no public key is provided
  • Add AuthUI class
  • Add Configs class

Version 1.1.1

  • Fix 'no remember in signinevent' when remember option is disabled

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit-rsa-auth-ui-1.1.1.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

streamlit_rsa_auth_ui-1.1.1-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file streamlit-rsa-auth-ui-1.1.1.tar.gz.

File metadata

  • Download URL: streamlit-rsa-auth-ui-1.1.1.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.19

File hashes

Hashes for streamlit-rsa-auth-ui-1.1.1.tar.gz
Algorithm Hash digest
SHA256 b7e845895a00700ca3d02835c8f4626d44f5f4f08af19733870684842dd1f1cd
MD5 311e34b2a5c57012eaa9bc4c12202bda
BLAKE2b-256 9568b57762a36c1c28389367785369105e1b3b6c7cded612405ebcf3207b7e3a

See more details on using hashes here.

File details

Details for the file streamlit_rsa_auth_ui-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_rsa_auth_ui-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec1db29b3b3801f33ac24fbd15cc7dbbe2cde7dd1b01ca4408bf749badd8c2e9
MD5 4b02119d9b95f439e26d0697c41c9865
BLAKE2b-256 0e646b8959ad5b90b3b0e303bd46c9d86671c81267fa8df4fd4cb799e4d23efe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page