OAuth2Util/OAuth2Util.py
def do_GET(self):
		"""
		Handle the retrieval of the code
		"""
		parsed_url = urlparse(self.path)

		if parsed_url[2] == "/" + SERVER_REDIRECT_PATH:  # 2 = Path
			parsed_query = parse_qs(parsed_url[4])  # 4 = Query

			if "code" not in parsed_query:
				self.send_response(200)
				self.send_header("Content-Type", "text/plain")
				self.end_headers()

				self.wfile.write("No code found, try again!".encode("utf-8"))
				return

			self.server.response_code = parsed_query["code"][0]

			self.send_response(200)
			self.send_header("Content-Type", "text/plain")
			self.end_headers()

			self.wfile.write(
				"Thank you for using OAuth2Util. The authorization was successful, "
				"you can now close this window.".encode("utf-8"))
		elif parsed_url[2] == "/" + SERVER_LINK_PATH: # 2 = Path
			self.send_response(200)
			self.send_header("Content-Type", "text/html")
			self.end_headers()

			self.wfile.write("<html><body>Hey there!<br/>Click <a href=\"{0}\">here</a> to claim your prize.</body></html>"
				.format(self.server.authorize_url).encode("utf-8"))
		else:
			self.send_response(404)
			self.send_header("Content-Type", "text/plain")
			self.end_headers()
			self.wfile.write("404 not found".encode("utf-8"))
def do_GET(self):
		"""
		Handle the retrieval of the code
		"""
		parsed_url = urlparse(self.path)

		if parsed_url[2] == "/" + SERVER_REDIRECT_PATH:  # 2 = Path
			parsed_query = parse_qs(parsed_url[4])  # 4 = Query

			if "code" not in parsed_query:
				self.send_response(200)
				self.send_header("Content-Type", "text/plain")
				self.end_headers()

				self.wfile.write("No code found, try again!".encode("utf-8"))
				return

			self.server.response_code = parsed_query["code"][0]

			self.send_response(200)
			self.send_header("Content-Type", "text/plain")
			self.end_headers()

			self.wfile.write(
				"Thank you for using OAuth2Util. The authorization was successful, "
				"you can now close this window.".encode("utf-8"))
		elif parsed_url[2] == "/" + SERVER_LINK_PATH: # 2 = Path
			self.send_response(200)
			self.send_header("Content-Type", "text/html")
			self.end_headers()

			self.wfile.write("<html><body>Hey there!<br/>Click <a href=\"{0}\">here</a> to claim your prize.</body></html>"
				.format(self.server.authorize_url).encode("utf-8"))
		else:
			self.send_response(404)
			self.send_header("Content-Type", "text/plain")
			self.end_headers()
			self.wfile.write("404 not found".encode("utf-8"))
def do_GET ( self ) : parsed_url = urlparse ( self . path ) if parsed_url [ 2 ] == "/" + SERVER_REDIRECT_PATH : # 2 = Path parsed_query = parse_qs ( parsed_url [ 4 ] ) # 4 = Query if "code" not in parsed_query : self . send_response ( 200 ) self . send_header ( "Content-Type" , "text/plain" ) self . end_headers ( ) self . wfile . write ( "No code found, try again!" . encode ( "utf-8" ) ) return self . server . response_code = parsed_query [ "code" ] [ 0 ] self . send_response ( 200 ) self . send_header ( "Content-Type" , "text/plain" ) self . end_headers ( ) self . wfile . write ( "Thank you for using OAuth2Util. The authorization was successful, " "you can now close this window." . encode ( "utf-8" ) ) elif parsed_url [ 2 ] == "/" + SERVER_LINK_PATH : # 2 = Path self . send_response ( 200 ) self . send_header ( "Content-Type" , "text/html" ) self . end_headers ( ) self . wfile . write ( "<html><body>Hey there!<br/>Click <a href=\"{0}\">here</a> to claim your prize.</body></html>" . format ( self . server . authorize_url ) . encode ( "utf-8" ) ) else : self . send_response ( 404 ) self . send_header ( "Content-Type" , "text/plain" ) self . end_headers ( ) self . wfile . write ( "404 not found" . encode ( "utf-8" ) )
Handle the retrieval of the code
Handle the retrieval of the code