Skip to content

Commit

Permalink
Change back to use print(result) in error path
Browse files Browse the repository at this point in the history
  • Loading branch information
rayluo committed Feb 21, 2024
1 parent 0d8b2c2 commit bf87155
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sample/confidential_client_certificate_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def acquire_and_use_token():
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
else:
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error


while True: # Here we mimic a long-lived daemon
Expand Down
2 changes: 1 addition & 1 deletion sample/confidential_client_secret_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def acquire_and_use_token():
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
else:
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error


while True: # Here we mimic a long-lived daemon
Expand Down
2 changes: 1 addition & 1 deletion sample/device_flow_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def acquire_and_use_token():
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
else:
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error


while True: # Here we mimic a long-lived daemon
Expand Down
2 changes: 1 addition & 1 deletion sample/interactive_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def acquire_and_use_token():
headers={'Authorization': 'Bearer ' + result['access_token']},)
print("Graph API call result: %s ..." % graph_response.text[:100])
else:
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error


while True: # Here we mimic a long-lived daemon
Expand Down
11 changes: 6 additions & 5 deletions sample/username_password_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"authority": "https://login.microsoftonline.com/organizations",
"client_id": "your_client_id came from https://learn.microsoft.com/entra/identity-platform/quickstart-register-app",
"username": "your_username@your_tenant.com",
"password": "This is a sample only. You better NOT persist your password.",
"scope": ["User.ReadBasic.All"],
// You can find the other permission names from this document
// https://docs.microsoft.com/en-us/graph/permissions-reference
Expand All @@ -20,6 +19,7 @@
"""

import sys # For simplicity, we'll read config file from 1st CLI param sys.argv[1]
import getpass
import json
import logging
import time
Expand All @@ -33,16 +33,18 @@
# logging.getLogger("msal").setLevel(logging.INFO) # Optionally disable MSAL DEBUG logs

config = json.load(open(sys.argv[1]))
config["password"] = getpass.getpass()

# If for whatever reason you plan to recreate same ClientApplication periodically,
# you shall create one global token cache and reuse it by each ClientApplication
global_token_cache = msal.TokenCache() # The TokenCache() is in-memory.
# See more options in https://msal-python.readthedocs.io/en/latest/#tokencache

# Create a preferably long-lived app instance, to avoid the overhead of app creation
global_app = msal.PublicClientApplication(
config["client_id"], authority=config["authority"],
global_app = msal.ClientApplication(
config["client_id"],
client_credential=config.get("client_secret"),
authority=config["authority"],
token_cache=global_token_cache, # Let this app (re)use an existing token cache.
# If absent, ClientApplication will create its own empty token cache
)
Expand Down Expand Up @@ -73,8 +75,7 @@ def acquire_and_use_token():
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
else:
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
print(result)
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error
if 65001 in result.get("error_codes", []): # Not mean to be coded programatically, but...
raise RuntimeError(
"AAD requires user consent for U/P flow to succeed. "
Expand Down
2 changes: 1 addition & 1 deletion sample/vault_jwt_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def acquire_and_use_token():
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
else:
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error


while True: # Here we mimic a long-lived daemon
Expand Down

0 comments on commit bf87155

Please sign in to comment.