@@ -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 , timeout = None ,
26+ ):
2527 """Creates an authority instance, and also validates it.
2628
2729 :param validate_authority:
@@ -30,24 +32,31 @@ 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
37+ self .timeout = timeout
3338 canonicalized , self .instance , tenant = canonicalize (authority_url )
3439 tenant_discovery_endpoint = ( # Hard code a V2 pattern as default value
3540 'https://{}/{}/v2.0/.well-known/openid-configuration'
3641 .format (WORLD_WIDE , tenant ))
3742 if validate_authority and self .instance not in WELL_KNOWN_AUTHORITY_HOSTS :
3843 tenant_discovery_endpoint = instance_discovery (
39- canonicalized + "/oauth2/v2.0/authorize" )
40- openid_config = tenant_discovery (tenant_discovery_endpoint )
44+ canonicalized + "/oauth2/v2.0/authorize" ,
45+ verify = verify , proxies = proxies , timeout = timeout )
46+ openid_config = tenant_discovery (
47+ tenant_discovery_endpoint ,
48+ verify = verify , proxies = proxies , timeout = timeout )
4149 self .authorization_endpoint = openid_config ['authorization_endpoint' ]
4250 self .token_endpoint = openid_config ['token_endpoint' ]
4351 _ , _ , self .tenant = canonicalize (self .token_endpoint ) # Usually a GUID
4452 self .is_adfs = self .tenant .lower () == 'adfs'
4553
46- def user_realm_discovery (self , username , ** kwargs ):
54+ def user_realm_discovery (self , username ):
4755 resp = requests .get (
4856 "https://{netloc}/common/userrealm/{username}?api-version=1.0" .format (
4957 netloc = self .instance , username = username ),
50- headers = {'Accept' :'application/json' }, ** kwargs )
58+ headers = {'Accept' :'application/json' },
59+ verify = self .verify , proxies = self .proxies , timeout = self .timeout )
5160 resp .raise_for_status ()
5261 return resp .json ()
5362 # It will typically contain "ver", "account_type",
@@ -64,17 +73,20 @@ def canonicalize(url):
6473 "https://login.microsoftonline.com/<tenant_name>" % url )
6574 return match_object .group (0 ), match_object .group (1 ), match_object .group (2 )
6675
67- def instance_discovery (url , response = None ): # Returns tenant discovery endpoint
76+ def instance_discovery (url , response = None , ** kwargs ):
77+ # Returns tenant discovery endpoint
6878 resp = requests .get ( # Note: This URL seemingly returns V1 endpoint only
6979 'https://{}/common/discovery/instance' .format (WORLD_WIDE ),
70- params = {'authorization_endpoint' : url , 'api-version' : '1.0' })
80+ params = {'authorization_endpoint' : url , 'api-version' : '1.0' },
81+ ** kwargs )
7182 payload = response or resp .json ()
7283 if 'tenant_discovery_endpoint' not in payload :
7384 raise MsalServiceError (status_code = resp .status_code , ** payload )
7485 return payload ['tenant_discovery_endpoint' ]
7586
76- def tenant_discovery (tenant_discovery_endpoint ): # Returns Openid Configuration
77- resp = requests .get (tenant_discovery_endpoint )
87+ def tenant_discovery (tenant_discovery_endpoint , ** kwargs ):
88+ # Returns Openid Configuration
89+ resp = requests .get (tenant_discovery_endpoint , ** kwargs )
7890 payload = resp .json ()
7991 if 'authorization_endpoint' in payload and 'token_endpoint' in payload :
8092 return payload
0 commit comments