-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
24 lines (20 loc) · 906 Bytes
/
Copy pathserver.py
File metadata and controls
24 lines (20 loc) · 906 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
import http.server
import asyncio
# Facebook Redirect handler class
class RedirectHandler(http.server.BaseHTTPRequestHandler):
def __init__(self, handle_authorization_response, *args, **kwargs):
self.handle_authorization_response = handle_authorization_response
super().__init__(*args, **kwargs)
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(b"<html><body><h1>Authorization successful</h1></body></html>")
asyncio.create_task(self.handle_authorization_response(self.path))
def start(handle_code_callback, host: str="localhost", port: int=3000):
server_address = (host, port)
httpd = http.server.HTTPServer(
server_address,
lambda *args, **kwargs: RedirectHandler(handle_code_callback, *args, **kwargs),
)
httpd.handle_request()