Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,6 +26,13 @@ def generate_pkce_codes():
|
|
| 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
|
|
@@ -46,6 +53,25 @@ client_instance = get_msal_app()
|
|
| 46 |
def get_access_token(code):
|
| 47 |
client_instance = get_msal_app()
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
st.write("Debug: MSAL App Configuration:")
|
| 50 |
st.write(f"Client ID: {APPLICATION_ID_KEY[:5]}...")
|
| 51 |
st.write(f"Authority: {AUTHORITY_URL}")
|
|
|
|
| 26 |
return code_verifier, code_challenge
|
| 27 |
|
| 28 |
def get_msal_app():
|
| 29 |
+
return msal.ConfidentialClientApplication(
|
| 30 |
+
client_id=APPLICATION_ID_KEY,
|
| 31 |
+
client_credential=CLIENT_SECRET_KEY,
|
| 32 |
+
authority=AUTHORITY_URL
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
def get_msal_app2():
|
| 36 |
return msal.PublicClientApplication(
|
| 37 |
client_id=APPLICATION_ID_KEY,
|
| 38 |
authority=AUTHORITY_URL
|
|
|
|
| 53 |
def get_access_token(code):
|
| 54 |
client_instance = get_msal_app()
|
| 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 |
+
|
| 72 |
+
def get_access_token3(code):
|
| 73 |
+
client_instance = get_msal_app()
|
| 74 |
+
|
| 75 |
st.write("Debug: MSAL App Configuration:")
|
| 76 |
st.write(f"Client ID: {APPLICATION_ID_KEY[:5]}...")
|
| 77 |
st.write(f"Authority: {AUTHORITY_URL}")
|