Skip to content

Commit b4e482b

Browse files
committed
fixup! Wire up verify and proxies for Authority
1 parent 583adeb commit b4e482b

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

msal/application.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(
9797
self.timeout = timeout
9898
self.authority = Authority(
9999
authority or "https://login.microsoftonline.com/common/",
100-
validate_authority, verify=self.verify, proxies=self.proxies)
100+
validate_authority, verify=verify, proxies=proxies, timeout=timeout)
101101
# Here the self.authority is not the same type as authority in input
102102
self.token_cache = token_cache or TokenCache()
103103
self.client = self._build_client(client_credential, self.authority)
@@ -167,7 +167,8 @@ def get_authorization_request_url(
167167
sending them on the wire.)
168168
"""
169169
the_authority = Authority(
170-
authority, verify=self.verify, proxies=self.proxies,
170+
authority,
171+
verify=self.verify, proxies=self.proxies, timeout=self.timeout,
171172
) if authority else self.authority
172173
client = Client(
173174
{"authorization_endpoint": the_authority.authorization_endpoint},
@@ -275,7 +276,8 @@ def acquire_token_silent(
275276
"""
276277
assert isinstance(scopes, list), "Invalid parameter type"
277278
the_authority = Authority(
278-
authority, verify=self.verify, proxies=self.proxies,
279+
authority,
280+
verify=self.verify, proxies=self.proxies, timeout=self.timeout,
279281
) if authority else self.authority
280282

281283
if not force_refresh:
@@ -393,7 +395,7 @@ def _acquire_token_by_username_password_federated(
393395
if user_realm_result.get("federation_metadata_url"):
394396
wstrust_endpoint = mex_send_request(
395397
user_realm_result["federation_metadata_url"],
396-
verify=self.verify, proxies=self.proxies)
398+
verify=verify, proxies=proxies)
397399
logger.debug("wstrust_endpoint = %s", wstrust_endpoint)
398400
wstrust_result = wst_send_request(
399401
username, password, user_realm_result.get("cloud_audience_urn"),

msal/authority.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Authority(object):
2222
TODO: It will also cache the previously-validated authority instances.
2323
"""
2424
def __init__(self, authority_url, validate_authority=True,
25-
verify=True, proxies=None,
25+
verify=True, proxies=None, timeout=None,
2626
):
2727
"""Creates an authority instance, and also validates it.
2828
@@ -34,16 +34,18 @@ def __init__(self, authority_url, validate_authority=True,
3434
"""
3535
self.verify = verify
3636
self.proxies = proxies
37+
self.timeout = timeout
3738
canonicalized, self.instance, tenant = canonicalize(authority_url)
3839
tenant_discovery_endpoint = ( # Hard code a V2 pattern as default value
3940
'https://{}/{}/v2.0/.well-known/openid-configuration'
4041
.format(WORLD_WIDE, tenant))
4142
if validate_authority and self.instance not in WELL_KNOWN_AUTHORITY_HOSTS:
4243
tenant_discovery_endpoint = instance_discovery(
4344
canonicalized + "/oauth2/v2.0/authorize",
44-
verify=verify, proxies=proxies)
45+
verify=verify, proxies=proxies, timeout=timeout)
4546
openid_config = tenant_discovery(
46-
tenant_discovery_endpoint, verify=verify, proxies=proxies)
47+
tenant_discovery_endpoint,
48+
verify=verify, proxies=proxies, timeout=timeout)
4749
self.authorization_endpoint = openid_config['authorization_endpoint']
4850
self.token_endpoint = openid_config['token_endpoint']
4951
_, _, self.tenant = canonicalize(self.token_endpoint) # Usually a GUID
@@ -54,7 +56,7 @@ def user_realm_discovery(self, username):
5456
"https://{netloc}/common/userrealm/{username}?api-version=1.0".format(
5557
netloc=self.instance, username=username),
5658
headers={'Accept':'application/json'},
57-
verify=self.verify, proxies=self.proxies)
59+
verify=self.verify, proxies=self.proxies, timeout=self.timeout)
5860
resp.raise_for_status()
5961
return resp.json()
6062
# It will typically contain "ver", "account_type",
@@ -71,20 +73,20 @@ def canonicalize(url):
7173
"https://login.microsoftonline.com/<tenant_name>" % url)
7274
return match_object.group(0), match_object.group(1), match_object.group(2)
7375

74-
def instance_discovery(url, response=None, verify=True, proxies=None):
76+
def instance_discovery(url, response=None, **kwargs):
7577
# Returns tenant discovery endpoint
7678
resp = requests.get( # Note: This URL seemingly returns V1 endpoint only
7779
'https://{}/common/discovery/instance'.format(WORLD_WIDE),
7880
params={'authorization_endpoint': url, 'api-version': '1.0'},
79-
verify=verify, proxies=proxies)
81+
**kwargs)
8082
payload = response or resp.json()
8183
if 'tenant_discovery_endpoint' not in payload:
8284
raise MsalServiceError(status_code=resp.status_code, **payload)
8385
return payload['tenant_discovery_endpoint']
8486

85-
def tenant_discovery(tenant_discovery_endpoint, verify=True, proxies=None):
87+
def tenant_discovery(tenant_discovery_endpoint, **kwargs):
8688
# Returns Openid Configuration
87-
resp = requests.get(tenant_discovery_endpoint, verify=verify, proxies=proxies)
89+
resp = requests.get(tenant_discovery_endpoint, **kwargs)
8890
payload = resp.json()
8991
if 'authorization_endpoint' in payload and 'token_endpoint' in payload:
9092
return payload

0 commit comments

Comments
 (0)