@@ -20,12 +20,20 @@ def do_GET(self):
2020
2121 query = self .path .split ("?" , 1 )[- 1 ]
2222 parsed = parse_qs (query , keep_blank_values = True )
23- self .server .query_params = {k : v [0 ] if isinstance (v , list ) and len (v ) == 1 else v for k , v in parsed .items ()}
23+ self .server .auth_response = {k : v [0 ] if isinstance (v , list ) and len (v ) == 1 else v for k , v in parsed .items ()}
24+ self ._send_success_response ()
2425
26+ def do_POST (self ):
27+ content_length = int (self .headers .get ("Content-Length" , 0 ))
28+ body = self .rfile .read (content_length ).decode ("utf-8" )
29+ parsed = parse_qs (body , keep_blank_values = True )
30+ self .server .auth_response = {k : v [0 ] if isinstance (v , list ) and len (v ) == 1 else v for k , v in parsed .items ()}
31+ self ._send_success_response ()
32+
33+ def _send_success_response (self ):
2534 self .send_response (200 )
2635 self .send_header ("Content-Type" , "text/html" )
2736 self .end_headers ()
28-
2937 self .wfile .write (b"Authentication complete. You can close this window." )
3038
3139 def log_message (self , format , * args ): # pylint: disable=redefined-builtin
@@ -35,14 +43,13 @@ def log_message(self, format, *args): # pylint: disable=redefined-builtin
3543class AuthCodeRedirectServer (HTTPServer ):
3644 """HTTP server that listens for the redirect request following an authorization code authentication"""
3745
38- query_params : Mapping [str , Any ] = {}
39-
4046 def __init__ (self , hostname : str , port : int , timeout : int ) -> None :
4147 HTTPServer .__init__ (self , (hostname , port ), AuthCodeRedirectHandler )
4248 self .timeout = timeout
49+ self .auth_response : Mapping [str , Any ] = {}
4350
4451 def wait_for_redirect (self ) -> Mapping [str , Any ]:
45- while not self .query_params :
52+ while not self .auth_response :
4653 try :
4754 self .handle_request ()
4855 except (IOError , ValueError ):
@@ -53,7 +60,7 @@ def wait_for_redirect(self) -> Mapping[str, Any]:
5360 self .server_close ()
5461
5562 # if we timed out, this returns an empty dict
56- return self .query_params
63+ return self .auth_response
5764
5865 def handle_timeout (self ):
5966 """Break the request-handling loop by tearing down the server"""
0 commit comments