Skip to content

Commit 9110eca

Browse files
committed
Use case-sensitive scope, reference SerializableTokenCache, and log behaviors for debugging
1 parent adcb637 commit 9110eca

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

sample/client_credential_sample.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
config["client_id"], authority=config["authority"],
3131
client_credential=config["secret"],
3232
# token_cache=... # Default cache is in memory only.
33-
# See SerializableTokenCache for more details.
33+
# You can learn how to use SerializableTokenCache from
34+
# https://msal-python.rtfd.io/en/latest/#msal.SerializableTokenCache
3435
)
3536

3637
# The pattern to acquire a token looks like this.
@@ -42,7 +43,7 @@
4243
result = app.acquire_token_silent(config["scope"], account=None)
4344

4445
if not result:
45-
# So no suitable token exists in cache. Let's get a new one from AAD.
46+
logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
4647
result = app.acquire_token_for_client(scopes=config["scope"])
4748

4849
if "access_token" in result:

sample/device_flow_sample.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"authority": "https://login.microsoftonline.com/organizations",
66
"client_id": "your_client_id",
7-
"scope": ["user.read"]
7+
"scope": ["User.Read"]
88
}
99
1010
You can then run this sample with a JSON configuration file:
@@ -28,7 +28,8 @@
2828
app = msal.PublicClientApplication(
2929
config["client_id"], authority=config["authority"],
3030
# token_cache=... # Default cache is in memory only.
31-
# See SerializableTokenCache for more details.
31+
# You can learn how to use SerializableTokenCache from
32+
# https://msal-python.rtfd.io/en/latest/#msal.SerializableTokenCache
3233
)
3334

3435
# The pattern to acquire a token looks like this.
@@ -39,7 +40,7 @@
3940
# We now check the cache to see if we have some end users signed in before.
4041
accounts = app.get_accounts()
4142
if accounts:
42-
# If so, you could then somehow display these accounts and let end user choose
43+
logging.info("Account(s) exists in cache, probably with token too. Let's try.")
4344
print("Pick the account you want to use to proceed:")
4445
for a in accounts:
4546
print(a["username"])
@@ -49,7 +50,7 @@
4950
result = app.acquire_token_silent(config["scope"], account=chosen)
5051

5152
if not result:
52-
# So no suitable token exists in cache. Let's get a new one from AAD.
53+
logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
5354
flow = app.initiate_device_flow(scopes=config["scope"])
5455
print(flow["message"])
5556
# Ideally you should wait here, in order to save some unnecessary polling

sample/username_password_sample.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"authority": "https://login.microsoftonline.com/organizations",
66
"client_id": "your_client_id",
77
"username": "your_username@your_tenant.com",
8-
"scope": ["user.read"],
8+
"scope": ["User.Read"],
99
"password": "This is a sample only. You better NOT persist your password."
1010
}
1111
@@ -30,7 +30,8 @@
3030
app = msal.PublicClientApplication(
3131
config["client_id"], authority=config["authority"],
3232
# token_cache=... # Default cache is in memory only.
33-
# See SerializableTokenCache for more details.
33+
# You can learn how to use SerializableTokenCache from
34+
# https://msal-python.rtfd.io/en/latest/#msal.SerializableTokenCache
3435
)
3536

3637
# The pattern to acquire a token looks like this.
@@ -39,11 +40,11 @@
3940
# Firstly, check the cache to see if this end user has signed in before
4041
accounts = app.get_accounts(username=config["username"])
4142
if accounts:
42-
# It means the account(s) exists in cache, probably with token too. Let's try.
43+
logging.info("Account(s) exists in cache, probably with token too. Let's try.")
4344
result = app.acquire_token_silent(config["scope"], account=accounts[0])
4445

4546
if not result:
46-
# So no suitable token exists in cache. Let's get a new one from AAD.
47+
logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
4748
result = app.acquire_token_by_username_password(
4849
config["username"], config["password"], scopes=config["scope"])
4950

0 commit comments

Comments
 (0)