18
18
19
19
logger = logging .getLogger (__name__ )
20
20
21
+ class IgnoreNetrcAuth (requests .auth .AuthBase ):
22
+ """This auth method is a no-op.
23
+
24
+ We use it to force requestslib to not use .netrc to write auth headers
25
+ when making .post() requests to the oauth token endpoints, since these
26
+ don't require authentication.
27
+
28
+ In cases where .netrc is outdated or corrupt, these requests will fail.
29
+
30
+ See issue #121
31
+ """
32
+ def __call__ (self , r ):
33
+ return r
21
34
22
35
class OAuthManager :
23
36
def __init__ (
@@ -43,7 +56,7 @@ def __fetch_well_known_config(self, hostname: str):
43
56
known_config_url = self .idp_endpoint .get_openid_config_url (hostname )
44
57
45
58
try :
46
- response = requests .get (url = known_config_url )
59
+ response = requests .get (url = known_config_url , auth = IgnoreNetrcAuth () )
47
60
except RequestException as e :
48
61
logger .error (
49
62
f"Unable to fetch OAuth configuration from { known_config_url } .\n "
@@ -149,7 +162,7 @@ def __send_token_request(token_request_url, data):
149
162
"Accept" : "application/json" ,
150
163
"Content-Type" : "application/x-www-form-urlencoded" ,
151
164
}
152
- response = requests .post (url = token_request_url , data = data , headers = headers )
165
+ response = requests .post (url = token_request_url , data = data , headers = headers , auth = IgnoreNetrcAuth () )
153
166
return response .json ()
154
167
155
168
def __send_refresh_token_request (self , hostname , refresh_token ):
0 commit comments