Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,28 @@ PRODUCT_SCOPES = {
|
|
22 |
|
23 |
BASE_SCOPES = ['User.Read']
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def make_api_call(access_token, endpoint, method='GET', data=None):
|
28 |
headers = {'Authorization': f'Bearer {access_token}', 'Content-Type': 'application/json'}
|
|
|
22 |
|
23 |
BASE_SCOPES = ['User.Read']
|
24 |
|
25 |
+
def get_msal_app():
|
26 |
+
return msal.ConfidentialClientApplication(
|
27 |
+
client_id=APPLICATION_ID_KEY,
|
28 |
+
client_credential=CLIENT_SECRET_KEY,
|
29 |
+
authority=AUTHORITY_URL
|
30 |
+
)
|
31 |
+
|
32 |
+
def get_access_token(code):
|
33 |
+
client_instance = get_msal_app()
|
34 |
+
try:
|
35 |
+
result = client_instance.acquire_token_by_authorization_code(
|
36 |
+
code=code,
|
37 |
+
scopes=st.session_state.get('request_scopes', BASE_SCOPES),
|
38 |
+
redirect_uri=REDIRECT_URI
|
39 |
+
)
|
40 |
+
if 'access_token' in result:
|
41 |
+
return result['access_token']
|
42 |
+
else:
|
43 |
+
raise Exception(f"Error acquiring token: {result.get('error_description')}")
|
44 |
+
except Exception as e:
|
45 |
+
st.error(f"Exception in get_access_token: {str(e)}")
|
46 |
+
raise
|
47 |
|
48 |
def make_api_call(access_token, endpoint, method='GET', data=None):
|
49 |
headers = {'Authorization': f'Bearer {access_token}', 'Content-Type': 'application/json'}
|