From f8dafeb5140549332b8a163080ebcdd12b4728f2 Mon Sep 17 00:00:00 2001 From: Pratham Soni Date: Fri, 21 Jun 2024 16:24:56 -0500 Subject: [PATCH 1/2] interface_1 change to st.download_button --- streamlit/interface_1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit/interface_1.py b/streamlit/interface_1.py index f41cf97..162273f 100644 --- a/streamlit/interface_1.py +++ b/streamlit/interface_1.py @@ -249,7 +249,7 @@ if client: buttons = st.columns([0.8, 0.2]) with buttons[0]: - st.download_button("Download Table", csv, "file.csv", "text/csv", key='download-csv') + st.download_button("Download Table", "file.csv", "text/csv", key='download-csv') with buttons[1]: if st.button("Run Doczy.AI Pipeline"): if not st.session_state.contract_count == len(edited_df): From 89d2deb515317a0003b5aacb5bf494c8d989640a Mon Sep 17 00:00:00 2001 From: Pratham Soni Date: Mon, 24 Jun 2024 10:13:32 -0500 Subject: [PATCH 2/2] session state for SSO auth --- streamlit/security.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/streamlit/security.py b/streamlit/security.py index d7465d2..2433203 100644 --- a/streamlit/security.py +++ b/streamlit/security.py @@ -2,6 +2,7 @@ import streamlit as st import msal import requests import boto3 +import secrets from botocore.exceptions import ClientError import json @@ -57,7 +58,11 @@ app = msal.ConfidentialClientApplication(CLIENT_ID, authority=AUTHORITY, client_ def get_auth_url(REDIRECT_URI): - auth_url = app.get_authorization_request_url(SCOPE, redirect_uri=REDIRECT_URI ) + #Generates a random stat parameter + state = secrets.token_urlsafe(16) + #Stores the state param in the session state + st.session_state['state'] = state + auth_url = app.get_authorization_request_url(SCOPE, redirect_uri=REDIRECT_URI, state=state) return auth_url @st.cache_data @@ -75,11 +80,13 @@ def get_user_info(access_token): def handle_redirect(REDIRECT_URI): if not st.session_state.get('access_token'): + query_params = st.experimental_get_query_params() code = st.query_params.get('code') - if code: - access_token = get_token_from_code(code, REDIRECT_URI) + state=query_params.get('state') + if code and state and state[0] == st.session_state.get('state'): + access_token = get_token_from_code(code[0], REDIRECT_URI) st.session_state['access_token'] = access_token - st.session_state + clear_url()