awacke1 commited on
Commit
7e087e0
·
verified ·
1 Parent(s): f08b405

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -22,7 +22,28 @@ PRODUCT_SCOPES = {
22
 
23
  BASE_SCOPES = ['User.Read']
24
 
25
- # ... (keep the get_msal_app and get_access_token functions as they were) ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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'}