Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -122,10 +122,54 @@ def get_access_token2(code, code_verifier=None):
|
|
| 122 |
except Exception as e:
|
| 123 |
st.error(f"Exception in get_access_token: {str(e)}")
|
| 124 |
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
-
def
|
| 129 |
# βοΈq= Run ArXiv search from query parameters
|
| 130 |
try:
|
| 131 |
query_params = st.query_params
|
|
@@ -198,20 +242,37 @@ def main():
|
|
| 198 |
process_query_params()
|
| 199 |
|
| 200 |
if 'access_token' not in st.session_state:
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
st.stop()
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
scopes=SCOPES,
|
| 209 |
-
redirect_uri=REDIRECT_URI,
|
| 210 |
-
code_challenge=code_challenge,
|
| 211 |
-
code_challenge_method="S256"
|
| 212 |
-
)
|
| 213 |
-
st.write('π Please [click here]({}) to log in and authorize the app.'.format(auth_url))
|
| 214 |
-
st.stop()
|
| 215 |
|
| 216 |
|
| 217 |
# π Sidebar navigation
|
|
|
|
| 122 |
except Exception as e:
|
| 123 |
st.error(f"Exception in get_access_token: {str(e)}")
|
| 124 |
raise
|
| 125 |
+
|
| 126 |
+
def clear_query_params():
|
| 127 |
+
# Get the current URL without query parameters
|
| 128 |
+
base_url = st.get_page_config().base_url_path
|
| 129 |
+
st.write(f'<meta http-equiv="refresh" content="0; url={base_url}">', unsafe_allow_html=True)
|
| 130 |
+
st.stop()
|
| 131 |
+
|
| 132 |
+
def process_query_params():
|
| 133 |
+
query_params = st.query_params
|
| 134 |
+
st.write("Debug: All query parameters:", query_params)
|
| 135 |
+
|
| 136 |
+
if 'error' in query_params:
|
| 137 |
+
error = query_params.get('error')
|
| 138 |
+
error_description = query_params.get('error_description', 'No description provided')
|
| 139 |
+
st.error(f"Authentication Error: {error}")
|
| 140 |
+
st.error(f"Error Description: {urllib.parse.unquote(error_description)}")
|
| 141 |
+
st.stop()
|
| 142 |
+
|
| 143 |
+
if 'code' in query_params:
|
| 144 |
+
code = query_params.get('code')
|
| 145 |
+
st.write('π Authorization Code Obtained:', code[:10] + '...')
|
| 146 |
+
|
| 147 |
+
try:
|
| 148 |
+
access_token = get_access_token(code)
|
| 149 |
+
st.session_state['access_token'] = access_token
|
| 150 |
+
st.success("Access token acquired successfully!")
|
| 151 |
+
# Redirect to clear query params
|
| 152 |
+
st.rerun()
|
| 153 |
+
except Exception as e:
|
| 154 |
+
st.error(f"Error acquiring access token: {str(e)}")
|
| 155 |
+
st.stop()
|
| 156 |
|
| 157 |
+
# Handle other query parameters as needed
|
| 158 |
+
if 'q' in query_params or 'query' in query_params:
|
| 159 |
+
query = query_params.get('q') or query_params.get('query')
|
| 160 |
+
if query:
|
| 161 |
+
# Process the query
|
| 162 |
+
pass
|
| 163 |
|
| 164 |
+
if 'action' in query_params:
|
| 165 |
+
action = query_params.get('action')
|
| 166 |
+
if action == 'show_message':
|
| 167 |
+
st.success("Showing a message because 'action=show_message' was found in the URL.")
|
| 168 |
+
elif action == 'clear':
|
| 169 |
+
# Instead of clearing query params, we'll redirect
|
| 170 |
+
st.rerun()
|
| 171 |
|
| 172 |
+
def process_query_params2():
|
| 173 |
# βοΈq= Run ArXiv search from query parameters
|
| 174 |
try:
|
| 175 |
query_params = st.query_params
|
|
|
|
| 242 |
process_query_params()
|
| 243 |
|
| 244 |
if 'access_token' not in st.session_state:
|
| 245 |
+
query_params = st.query_params
|
| 246 |
+
if 'code' in query_params:
|
| 247 |
+
code = query_params.get('code')
|
| 248 |
+
st.write('π Authorization Code Obtained:', code[:10] + '...')
|
| 249 |
+
|
| 250 |
+
try:
|
| 251 |
+
access_token = get_access_token(code)
|
| 252 |
+
st.session_state['access_token'] = access_token
|
| 253 |
+
st.success("Access token acquired successfully!")
|
| 254 |
+
# Instead of clearing query params, we'll redirect to remove them
|
| 255 |
+
st.rerun()
|
| 256 |
+
except Exception as e:
|
| 257 |
+
if "AADSTS70000" in str(e) and "code has expired" in str(e):
|
| 258 |
+
st.error("The authorization code has expired. Please log in again.")
|
| 259 |
+
st.session_state.pop('access_token', None)
|
| 260 |
+
# Redirect to clear query params
|
| 261 |
+
st.rerun()
|
| 262 |
+
else:
|
| 263 |
+
st.error(f"Error acquiring access token: {str(e)}")
|
| 264 |
+
st.stop()
|
| 265 |
+
else:
|
| 266 |
+
client_instance = get_msal_app()
|
| 267 |
+
authorization_url = client_instance.get_authorization_request_url(
|
| 268 |
+
scopes=SCOPES,
|
| 269 |
+
redirect_uri=REDIRECT_URI
|
| 270 |
+
)
|
| 271 |
+
st.write('π Please [click here]({}) to log in and authorize the app.'.format(authorization_url))
|
| 272 |
st.stop()
|
| 273 |
+
else:
|
| 274 |
+
# Rest of your code for authenticated users
|
| 275 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
|
| 278 |
# π Sidebar navigation
|