Refat81 commited on
Commit
965cf87
Β·
verified Β·
1 Parent(s): 357899b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -6
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py - COMPLETE Google OAuth Version
2
  import streamlit as st
3
  import requests
4
  import json
@@ -96,15 +96,31 @@ class SessionManager:
96
  session_data["signature"] = self._sign_session(session_data)
97
 
98
  # ============================================
99
- # PAGE FUNCTIONS
100
  # ============================================
101
 
102
  def handle_oauth_callback():
103
- """Handle OAuth callback"""
104
- query_params = st.query_params
 
 
 
 
 
 
 
 
105
 
106
  if "code" in query_params:
107
- code = query_params["code"]
 
 
 
 
 
 
 
 
108
 
109
  with st.spinner("πŸ” Authenticating..."):
110
  # Exchange code for tokens
@@ -134,7 +150,11 @@ def handle_oauth_callback():
134
  st.session_state.authenticated = True
135
 
136
  # Clear URL parameters
137
- st.query_params.clear()
 
 
 
 
138
  st.rerun()
139
  else:
140
  st.error("❌ Authentication failed")
@@ -147,6 +167,10 @@ def is_authenticated():
147
  session_mgr = SessionManager()
148
  return session_mgr.verify_session(st.session_state.session)
149
 
 
 
 
 
150
  def login_page():
151
  """Display login page"""
152
  st.set_page_config(page_title="Login", page_icon="πŸ”’", layout="centered")
 
1
+ # app.py - COMPLETE Google OAuth Version with Backward Compatibility
2
  import streamlit as st
3
  import requests
4
  import json
 
96
  session_data["signature"] = self._sign_session(session_data)
97
 
98
  # ============================================
99
+ # OAUTH CALLBACK HANDLER (FIXED)
100
  # ============================================
101
 
102
  def handle_oauth_callback():
103
+ """Handle OAuth callback - compatible with all Streamlit versions"""
104
+ # Get query params (backward compatible)
105
+ try:
106
+ # Streamlit 1.28+ method
107
+ query_params = st.query_params
108
+ is_new_streamlit = True
109
+ except AttributeError:
110
+ # Streamlit <1.28 method
111
+ query_params = st.experimental_get_query_params()
112
+ is_new_streamlit = False
113
 
114
  if "code" in query_params:
115
+ # Extract code (different format in old vs new API)
116
+ if is_new_streamlit:
117
+ code = query_params.get("code", "")
118
+ else:
119
+ code_list = query_params.get("code", [])
120
+ code = code_list[0] if code_list else ""
121
+
122
+ if not code:
123
+ return
124
 
125
  with st.spinner("πŸ” Authenticating..."):
126
  # Exchange code for tokens
 
150
  st.session_state.authenticated = True
151
 
152
  # Clear URL parameters
153
+ if is_new_streamlit:
154
+ st.query_params.clear()
155
+ else:
156
+ st.experimental_set_query_params()
157
+
158
  st.rerun()
159
  else:
160
  st.error("❌ Authentication failed")
 
167
  session_mgr = SessionManager()
168
  return session_mgr.verify_session(st.session_state.session)
169
 
170
+ # ============================================
171
+ # PAGE FUNCTIONS
172
+ # ============================================
173
+
174
  def login_page():
175
  """Display login page"""
176
  st.set_page_config(page_title="Login", page_icon="πŸ”’", layout="centered")