Skip to content

Commit a3e85fc

Browse files
committed
Improve error message on incorrect authority uri
1 parent 364dfec commit a3e85fc

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ Before using MSAL Python (or any MSAL SDKs, for that matter), you will have to
3535
[register your application with the Microsoft identity platform](https://docs.microsoft.com/azure/active-directory/develop/quickstart-v2-register-an-app).
3636

3737
Acquiring tokens with MSAL Python follows this 3-step pattern.
38+
(Note: That is the high level conceptual pattern.
39+
There will be some variations for different flows. They are demonstrated in
40+
[runnable samples hosted right in this repo](https://github.com/AzureAD/microsoft-authentication-library-for-python/tree/dev/sample).
41+
)
42+
3843

3944
1. MSAL proposes a clean separation between
4045
[public client applications, and confidential client applications](https://tools.ietf.org/html/rfc6749#section-2.1).
@@ -43,7 +48,9 @@ Acquiring tokens with MSAL Python follows this 3-step pattern.
4348

4449
```python
4550
from msal import PublicClientApplication
46-
app = PublicClientApplication("your_client_id", authority="...")
51+
app = PublicClientApplication(
52+
"your_client_id",
53+
"authority": "https://login.microsoftonline.com/Enter_the_Tenant_Name_Here")
4754
```
4855

4956
Later, each time you would want an access token, you start by:
@@ -67,7 +74,7 @@ Acquiring tokens with MSAL Python follows this 3-step pattern.
6774
# Assuming the end user chose this one
6875
chosen = accounts[0]
6976
# Now let's try to find a token in cache for this account
70-
result = app.acquire_token_silent(config["scope"], account=chosen)
77+
result = app.acquire_token_silent(["your_scope"], account=chosen)
7178
```
7279

7380
3. Either there is no suitable token in the cache, or you chose to skip the previous step,
@@ -86,9 +93,6 @@ Acquiring tokens with MSAL Python follows this 3-step pattern.
8693
print(result.get("correlation_id")) # You may need this when reporting a bug
8794
```
8895

89-
That is the high level pattern. There will be some variations for different flows. They are demonstrated in
90-
[samples hosted right in this repo](https://github.com/AzureAD/microsoft-authentication-library-for-python/tree/dev/sample).
91-
9296
Refer the [Wiki](https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki) pages for more details on the MSAL Python functionality and usage.
9397

9498
## Migrating from ADAL

msal/authority.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,16 @@ def __init__(self, authority_url, http_client, validate_authority=True):
7979
authority.path, # In B2C scenario, it is "/tenant/policy"
8080
"" if tenant == "adfs" else "/v2.0" # the AAD v2 endpoint
8181
))
82-
openid_config = tenant_discovery(
83-
tenant_discovery_endpoint,
84-
self.http_client)
82+
try:
83+
openid_config = tenant_discovery(
84+
tenant_discovery_endpoint,
85+
self.http_client)
86+
except json.decoder.JSONDecodeError:
87+
raise ValueError(
88+
"Unable to get authority configuration for {}. "
89+
"Authority would typically be in a format of "
90+
"https://login.microsoftonline.com/your_tenant_name".format(
91+
authority_url))
8592
logger.debug("openid_config = %s", openid_config)
8693
self.authorization_endpoint = openid_config['authorization_endpoint']
8794
self.token_endpoint = openid_config['token_endpoint']

0 commit comments

Comments
 (0)