awacke1 commited on
Commit
12778c3
ยท
verified ยท
1 Parent(s): 043c6a0

Update backup.PrettyClose.app.py

Browse files
Files changed (1) hide show
  1. backup.PrettyClose.app.py +6 -7
backup.PrettyClose.app.py CHANGED
@@ -33,9 +33,8 @@ PRODUCT_SCOPES = {
33
  "๐Ÿ”— Azure OpenAI Service": ['AzureAIServices.ReadWrite.All']
34
  }
35
 
36
- # Separate reserved scopes
37
- RESERVED_SCOPES = ['openid', 'profile', 'offline_access']
38
- BASE_SCOPES = ['User.Read'] # Non-reserved base scopes
39
 
40
  def generate_pkce_codes():
41
  code_verifier = secrets.token_urlsafe(128)[:128]
@@ -54,7 +53,7 @@ def get_access_token(code, code_verifier):
54
  try:
55
  result = client_instance.acquire_token_by_authorization_code(
56
  code=code,
57
- scopes=st.session_state.get('all_scopes', BASE_SCOPES + RESERVED_SCOPES),
58
  redirect_uri=REDIRECT_URI,
59
  code_verifier=code_verifier
60
  )
@@ -86,8 +85,8 @@ def main():
86
  request_scopes.extend(PRODUCT_SCOPES[product])
87
  request_scopes = list(set(request_scopes)) # Remove duplicates
88
 
89
- # Store all scopes (including reserved) for token acquisition
90
- st.session_state['all_scopes'] = request_scopes + RESERVED_SCOPES
91
 
92
  if 'access_token' not in st.session_state:
93
  if 'code_verifier' not in st.session_state:
@@ -99,7 +98,7 @@ def main():
99
 
100
  client_instance = get_msal_app()
101
  auth_url = client_instance.get_authorization_request_url(
102
- scopes=request_scopes, # Use only non-reserved scopes for the auth request
103
  redirect_uri=REDIRECT_URI,
104
  code_challenge=code_challenge,
105
  code_challenge_method="S256"
 
33
  "๐Ÿ”— Azure OpenAI Service": ['AzureAIServices.ReadWrite.All']
34
  }
35
 
36
+ # Base scopes (non-reserved)
37
+ BASE_SCOPES = ['User.Read']
 
38
 
39
  def generate_pkce_codes():
40
  code_verifier = secrets.token_urlsafe(128)[:128]
 
53
  try:
54
  result = client_instance.acquire_token_by_authorization_code(
55
  code=code,
56
+ scopes=st.session_state.get('request_scopes', BASE_SCOPES),
57
  redirect_uri=REDIRECT_URI,
58
  code_verifier=code_verifier
59
  )
 
85
  request_scopes.extend(PRODUCT_SCOPES[product])
86
  request_scopes = list(set(request_scopes)) # Remove duplicates
87
 
88
+ # Store request scopes in session state
89
+ st.session_state['request_scopes'] = request_scopes
90
 
91
  if 'access_token' not in st.session_state:
92
  if 'code_verifier' not in st.session_state:
 
98
 
99
  client_instance = get_msal_app()
100
  auth_url = client_instance.get_authorization_request_url(
101
+ scopes=request_scopes,
102
  redirect_uri=REDIRECT_URI,
103
  code_challenge=code_challenge,
104
  code_challenge_method="S256"