Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,13 +20,18 @@ SCOPES = ['User.Read', 'Calendars.ReadWrite', 'Mail.ReadWrite', 'Notes.ReadWrite
|
|
20 |
|
21 |
# New function to generate PKCE code verifier and challenge
|
22 |
def generate_pkce_codes():
|
23 |
-
code_verifier = secrets.token_urlsafe(
|
24 |
code_challenge = base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode()).digest()).decode().rstrip('=')
|
25 |
return code_verifier, code_challenge
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
28 |
# ๐ ๏ธ Initialize the MSAL client
|
29 |
-
def
|
30 |
return msal.ConfidentialClientApplication(
|
31 |
client_id=APPLICATION_ID_KEY,
|
32 |
client_credential=CLIENT_SECRET_KEY,
|
@@ -104,7 +109,6 @@ def process_query_params():
|
|
104 |
st.write('๐ Authorization Code Obtained:', code[:10] + '...')
|
105 |
|
106 |
try:
|
107 |
-
# Retrieve the code verifier from session state
|
108 |
code_verifier = st.session_state.get('code_verifier')
|
109 |
if not code_verifier:
|
110 |
st.error("Code verifier not found in session state.")
|
@@ -113,6 +117,8 @@ def process_query_params():
|
|
113 |
access_token = get_access_token(code, code_verifier)
|
114 |
st.session_state['access_token'] = access_token
|
115 |
st.success("Access token acquired successfully!")
|
|
|
|
|
116 |
st.rerun()
|
117 |
except Exception as e:
|
118 |
st.error(f"Error acquiring access token: {str(e)}")
|
|
|
20 |
|
21 |
# New function to generate PKCE code verifier and challenge
|
22 |
def generate_pkce_codes():
|
23 |
+
code_verifier = secrets.token_urlsafe(128)[:128]
|
24 |
code_challenge = base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode()).digest()).decode().rstrip('=')
|
25 |
return code_verifier, code_challenge
|
26 |
|
27 |
+
def get_msal_app(code_challenge=None):
|
28 |
+
return msal.PublicClientApplication(
|
29 |
+
client_id=APPLICATION_ID_KEY,
|
30 |
+
authority=AUTHORITY_URL
|
31 |
+
)
|
32 |
+
|
33 |
# ๐ ๏ธ Initialize the MSAL client
|
34 |
+
def get_msal_app_old():
|
35 |
return msal.ConfidentialClientApplication(
|
36 |
client_id=APPLICATION_ID_KEY,
|
37 |
client_credential=CLIENT_SECRET_KEY,
|
|
|
109 |
st.write('๐ Authorization Code Obtained:', code[:10] + '...')
|
110 |
|
111 |
try:
|
|
|
112 |
code_verifier = st.session_state.get('code_verifier')
|
113 |
if not code_verifier:
|
114 |
st.error("Code verifier not found in session state.")
|
|
|
117 |
access_token = get_access_token(code, code_verifier)
|
118 |
st.session_state['access_token'] = access_token
|
119 |
st.success("Access token acquired successfully!")
|
120 |
+
# Clear the code from the URL
|
121 |
+
st.experimental_set_query_params()
|
122 |
st.rerun()
|
123 |
except Exception as e:
|
124 |
st.error(f"Error acquiring access token: {str(e)}")
|