-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback_server.py
More file actions
28 lines (23 loc) · 945 Bytes
/
Copy pathcallback_server.py
File metadata and controls
28 lines (23 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# callback_server.py
from http.server import BaseHTTPRequestHandler, HTTPServer
import urllib.parse
class CallbackHandler(BaseHTTPRequestHandler):
def do_GET(self):
parsed_path = urllib.parse.urlparse(self.path)
params = urllib.parse.parse_qs(parsed_path.query)
auth_code = params.get('code', [None])[0]
if auth_code:
print(f"\nAuthorization Code erhalten:\n{auth_code}\n")
message = "Authorization successful. You can close this window."
else:
message = "No code received."
self.send_response(200)
self.end_headers()
self.wfile.write(message.encode())
def run(server_class=HTTPServer, handler_class=CallbackHandler):
server_address = ('', 3000)
httpd = server_class(server_address, handler_class)
print("Callback-Server läuft unter http://localhost:3000 ...")
httpd.serve_forever()
if __name__ == '__main__':
run()