@@ -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