Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ def generate_pkce_codes():
|
|
| 25 |
code_challenge = base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode()).digest()).decode().rstrip('=')
|
| 26 |
return code_verifier, code_challenge
|
| 27 |
|
| 28 |
-
def get_msal_app(
|
| 29 |
return msal.PublicClientApplication(
|
| 30 |
client_id=APPLICATION_ID_KEY,
|
| 31 |
authority=AUTHORITY_URL
|
|
@@ -43,34 +43,7 @@ else:
|
|
| 43 |
# Create the MSAL instance for acquiring tokens
|
| 44 |
client_instance = get_msal_app()
|
| 45 |
|
| 46 |
-
# ๐ Acquire access token using authorization code
|
| 47 |
-
def get_access_token(code):
|
| 48 |
-
client_instance = get_msal_app()
|
| 49 |
-
|
| 50 |
-
# Debug: Print MSAL app configuration (be careful not to expose secrets)
|
| 51 |
-
st.write("Debug: MSAL App Configuration:")
|
| 52 |
-
st.write(f"Client ID: {APPLICATION_ID_KEY[:5]}...") # Show first 5 chars
|
| 53 |
-
st.write(f"Authority: {AUTHORITY_URL}")
|
| 54 |
-
st.write(f"Redirect URI: {REDIRECT_URI}")
|
| 55 |
-
|
| 56 |
-
try:
|
| 57 |
-
result = client_instance.acquire_token_by_authorization_code(
|
| 58 |
-
code=code,
|
| 59 |
-
scopes=SCOPES,
|
| 60 |
-
redirect_uri=REDIRECT_URI
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
if 'access_token' in result:
|
| 64 |
-
return result['access_token']
|
| 65 |
-
else:
|
| 66 |
-
error_description = result.get('error_description', 'No error description provided')
|
| 67 |
-
raise Exception(f"Error acquiring token: {error_description}")
|
| 68 |
-
except Exception as e:
|
| 69 |
-
st.error(f"Exception in get_access_token: {str(e)}")
|
| 70 |
-
raise
|
| 71 |
-
#st.stop()
|
| 72 |
-
|
| 73 |
-
|
| 74 |
def get_access_token(code, code_verifier):
|
| 75 |
client_instance = get_msal_app()
|
| 76 |
|
|
@@ -80,11 +53,13 @@ def get_access_token(code, code_verifier):
|
|
| 80 |
st.write(f"Redirect URI: {REDIRECT_URI}")
|
| 81 |
|
| 82 |
try:
|
|
|
|
| 83 |
result = client_instance.acquire_token_by_authorization_code(
|
| 84 |
code=code,
|
| 85 |
scopes=SCOPES,
|
| 86 |
redirect_uri=REDIRECT_URI,
|
| 87 |
-
|
|
|
|
| 88 |
)
|
| 89 |
|
| 90 |
if 'access_token' in result:
|
|
@@ -95,6 +70,7 @@ def get_access_token(code, code_verifier):
|
|
| 95 |
except Exception as e:
|
| 96 |
st.error(f"Exception in get_access_token: {str(e)}")
|
| 97 |
raise
|
|
|
|
| 98 |
|
| 99 |
def process_query_params():
|
| 100 |
# โ๏ธq= Run ArXiv search from query parameters
|
|
|
|
| 25 |
code_challenge = base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode()).digest()).decode().rstrip('=')
|
| 26 |
return code_verifier, code_challenge
|
| 27 |
|
| 28 |
+
def get_msal_app():
|
| 29 |
return msal.PublicClientApplication(
|
| 30 |
client_id=APPLICATION_ID_KEY,
|
| 31 |
authority=AUTHORITY_URL
|
|
|
|
| 43 |
# Create the MSAL instance for acquiring tokens
|
| 44 |
client_instance = get_msal_app()
|
| 45 |
|
| 46 |
+
# ๐ Acquire access token using authorization code and PKCE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
def get_access_token(code, code_verifier):
|
| 48 |
client_instance = get_msal_app()
|
| 49 |
|
|
|
|
| 53 |
st.write(f"Redirect URI: {REDIRECT_URI}")
|
| 54 |
|
| 55 |
try:
|
| 56 |
+
# Use PublicClientApplication to support PKCE
|
| 57 |
result = client_instance.acquire_token_by_authorization_code(
|
| 58 |
code=code,
|
| 59 |
scopes=SCOPES,
|
| 60 |
redirect_uri=REDIRECT_URI,
|
| 61 |
+
# If your MSAL library supports PKCE, this will work:
|
| 62 |
+
code_verifier=code_verifier
|
| 63 |
)
|
| 64 |
|
| 65 |
if 'access_token' in result:
|
|
|
|
| 70 |
except Exception as e:
|
| 71 |
st.error(f"Exception in get_access_token: {str(e)}")
|
| 72 |
raise
|
| 73 |
+
|
| 74 |
|
| 75 |
def process_query_params():
|
| 76 |
# โ๏ธq= Run ArXiv search from query parameters
|