17
17
18
18
logger = logging .getLogger (__name__ )
19
19
20
+ class IgnoreNetrcAuth (requests .auth .AuthBase ):
21
+ """This auth method is a no-op.
22
+
23
+ We use it to force requestslib to not use .netrc to write auth headers
24
+ when making .post() requests to the oauth token endpoints, since these
25
+ don't require authentication.
26
+
27
+ In cases where .netrc is outdated or corrupt, these requests will fail.
28
+
29
+ See issue #121
30
+ """
31
+ def __call__ (self , r ):
32
+ return r
20
33
21
34
class OAuthManager :
22
35
OIDC_REDIRECTOR_PATH = "oidc"
@@ -38,7 +51,7 @@ def __get_redirect_url(redirect_port: int):
38
51
def __fetch_well_known_config (idp_url : str ):
39
52
known_config_url = f"{ idp_url } /.well-known/oauth-authorization-server"
40
53
try :
41
- response = requests .get (url = known_config_url )
54
+ response = requests .get (url = known_config_url , auth = IgnoreNetrcAuth () )
42
55
except RequestException as e :
43
56
logger .error (
44
57
f"Unable to fetch OAuth configuration from { idp_url } .\n "
@@ -150,7 +163,7 @@ def __send_token_request(token_request_url, data):
150
163
"Accept" : "application/json" ,
151
164
"Content-Type" : "application/x-www-form-urlencoded" ,
152
165
}
153
- response = requests .post (url = token_request_url , data = data , headers = headers )
166
+ response = requests .post (url = token_request_url , data = data , headers = headers , auth = IgnoreNetrcAuth () )
154
167
return response .json ()
155
168
156
169
def __send_refresh_token_request (self , hostname , refresh_token ):
0 commit comments