@@ -21,7 +21,9 @@ class Authority(object):
2121 Once constructed, it contains members named "*_endpoint" for this instance.
2222 TODO: It will also cache the previously-validated authority instances.
2323 """
24- def __init__ (self , authority_url , validate_authority = True ):
24+ def __init__ (self , authority_url , validate_authority = True ,
25+ verify = True , proxies = None ,
26+ ):
2527 """Creates an authority instance, and also validates it.
2628
2729 :param validate_authority:
@@ -30,24 +32,29 @@ def __init__(self, authority_url, validate_authority=True):
3032 This parameter only controls whether an instance discovery will be
3133 performed.
3234 """
35+ self .verify = verify
36+ self .proxies = proxies
3337 canonicalized , self .instance , tenant = canonicalize (authority_url )
3438 tenant_discovery_endpoint = ( # Hard code a V2 pattern as default value
3539 'https://{}/{}/v2.0/.well-known/openid-configuration'
3640 .format (WORLD_WIDE , tenant ))
3741 if validate_authority and self .instance not in WELL_KNOWN_AUTHORITY_HOSTS :
3842 tenant_discovery_endpoint = instance_discovery (
39- canonicalized + "/oauth2/v2.0/authorize" )
40- openid_config = tenant_discovery (tenant_discovery_endpoint )
43+ canonicalized + "/oauth2/v2.0/authorize" ,
44+ verify = verify , proxies = proxies )
45+ openid_config = tenant_discovery (
46+ tenant_discovery_endpoint , verify = verify , proxies = proxies )
4147 self .authorization_endpoint = openid_config ['authorization_endpoint' ]
4248 self .token_endpoint = openid_config ['token_endpoint' ]
4349 _ , _ , self .tenant = canonicalize (self .token_endpoint ) # Usually a GUID
4450 self .is_adfs = self .tenant .lower () == 'adfs'
4551
46- def user_realm_discovery (self , username , ** kwargs ):
52+ def user_realm_discovery (self , username ):
4753 resp = requests .get (
4854 "https://{netloc}/common/userrealm/{username}?api-version=1.0" .format (
4955 netloc = self .instance , username = username ),
50- headers = {'Accept' :'application/json' }, ** kwargs )
56+ headers = {'Accept' :'application/json' },
57+ verify = self .verify , proxies = self .proxies )
5158 resp .raise_for_status ()
5259 return resp .json ()
5360 # It will typically contain "ver", "account_type",
@@ -64,17 +71,20 @@ def canonicalize(url):
6471 "https://login.microsoftonline.com/<tenant_name>" % url )
6572 return match_object .group (0 ), match_object .group (1 ), match_object .group (2 )
6673
67- def instance_discovery (url , response = None ): # Returns tenant discovery endpoint
74+ def instance_discovery (url , response = None , verify = True , proxies = None ):
75+ # Returns tenant discovery endpoint
6876 resp = requests .get ( # Note: This URL seemingly returns V1 endpoint only
6977 'https://{}/common/discovery/instance' .format (WORLD_WIDE ),
70- params = {'authorization_endpoint' : url , 'api-version' : '1.0' })
78+ params = {'authorization_endpoint' : url , 'api-version' : '1.0' },
79+ verify = verify , proxies = proxies )
7180 payload = response or resp .json ()
7281 if 'tenant_discovery_endpoint' not in payload :
7382 raise MsalServiceError (status_code = resp .status_code , ** payload )
7483 return payload ['tenant_discovery_endpoint' ]
7584
76- def tenant_discovery (tenant_discovery_endpoint ): # Returns Openid Configuration
77- resp = requests .get (tenant_discovery_endpoint )
85+ def tenant_discovery (tenant_discovery_endpoint , verify = True , proxies = None ):
86+ # Returns Openid Configuration
87+ resp = requests .get (tenant_discovery_endpoint , verify = verify , proxies = proxies )
7888 payload = resp .json ()
7989 if 'authorization_endpoint' in payload and 'token_endpoint' in payload :
8090 return payload
0 commit comments