1919logger = logging .getLogger (__name__ )
2020
2121
22+ class IgnoreNetrcAuth (requests .auth .AuthBase ):
23+ """This auth method is a no-op.
24+
25+ We use it to force requestslib to not use .netrc to write auth headers
26+ when making .post() requests to the oauth token endpoints, since these
27+ don't require authentication.
28+
29+ In cases where .netrc is outdated or corrupt, these requests will fail.
30+
31+ See issue #121
32+ """
33+
34+ def __call__ (self , r ):
35+ return r
36+
37+
2238class OAuthManager :
2339 def __init__ (
2440 self ,
@@ -43,7 +59,7 @@ def __fetch_well_known_config(self, hostname: str):
4359 known_config_url = self .idp_endpoint .get_openid_config_url (hostname )
4460
4561 try :
46- response = requests .get (url = known_config_url )
62+ response = requests .get (url = known_config_url , auth = IgnoreNetrcAuth () )
4763 except RequestException as e :
4864 logger .error (
4965 f"Unable to fetch OAuth configuration from { known_config_url } .\n "
@@ -149,7 +165,9 @@ def __send_token_request(token_request_url, data):
149165 "Accept" : "application/json" ,
150166 "Content-Type" : "application/x-www-form-urlencoded" ,
151167 }
152- response = requests .post (url = token_request_url , data = data , headers = headers )
168+ response = requests .post (
169+ url = token_request_url , data = data , headers = headers , auth = IgnoreNetrcAuth ()
170+ )
153171 return response .json ()
154172
155173 def __send_refresh_token_request (self , hostname , refresh_token ):
0 commit comments