Skip to content

Commit bf87155

Browse files
committed
Change back to use print(result) in error path
1 parent 0d8b2c2 commit bf87155

6 files changed

+11
-10
lines changed

sample/confidential_client_certificate_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def acquire_and_use_token():
7070
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
7171
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
7272
else:
73-
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
73+
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error
7474

7575

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

sample/confidential_client_secret_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def acquire_and_use_token():
6969
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
7070
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
7171
else:
72-
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
72+
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error
7373

7474

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

sample/device_flow_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def acquire_and_use_token():
9191
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
9292
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
9393
else:
94-
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
94+
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error
9595

9696

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

sample/interactive_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def acquire_and_use_token():
8686
headers={'Authorization': 'Bearer ' + result['access_token']},)
8787
print("Graph API call result: %s ..." % graph_response.text[:100])
8888
else:
89-
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
89+
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error
9090

9191

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

sample/username_password_sample.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"authority": "https://login.microsoftonline.com/organizations",
66
"client_id": "your_client_id came from https://learn.microsoft.com/entra/identity-platform/quickstart-register-app",
77
"username": "your_username@your_tenant.com",
8-
"password": "This is a sample only. You better NOT persist your password.",
98
"scope": ["User.ReadBasic.All"],
109
// You can find the other permission names from this document
1110
// https://docs.microsoft.com/en-us/graph/permissions-reference
@@ -20,6 +19,7 @@
2019
"""
2120

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

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

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

4243
# Create a preferably long-lived app instance, to avoid the overhead of app creation
43-
global_app = msal.PublicClientApplication(
44-
config["client_id"], authority=config["authority"],
44+
global_app = msal.ClientApplication(
45+
config["client_id"],
4546
client_credential=config.get("client_secret"),
47+
authority=config["authority"],
4648
token_cache=global_token_cache, # Let this app (re)use an existing token cache.
4749
# If absent, ClientApplication will create its own empty token cache
4850
)
@@ -73,8 +75,7 @@ def acquire_and_use_token():
7375
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
7476
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
7577
else:
76-
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
77-
print(result)
78+
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error
7879
if 65001 in result.get("error_codes", []): # Not mean to be coded programatically, but...
7980
raise RuntimeError(
8081
"AAD requires user consent for U/P flow to succeed. "

sample/vault_jwt_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def acquire_and_use_token():
132132
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
133133
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
134134
else:
135-
print("Token acquisition failed") # Examine result["error_description"] etc. to diagnose error
135+
print("Token acquisition failed", result) # Examine result["error_description"] etc. to diagnose error
136136

137137

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

0 commit comments

Comments
 (0)