Skip to content

Instantly share code, notes, and snippets.

@iwconfig
Created January 17, 2019 11:31
Show Gist options
  • Save iwconfig/bade5ea23c624c8bb0fc5e10df94892a to your computer and use it in GitHub Desktop.
Save iwconfig/bade5ea23c624c8bb0fc5e10df94892a to your computer and use it in GitHub Desktop.
simple callback server for oauth2. quits itself once code is retrieved
import threading, webbrowser
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse, parse_qs
class S(BaseHTTPRequestHandler):
def do_GET(self):
code = parse_qs(urlparse(self.path).query)['code'][0]
threading.Thread(target=httpd.shutdown, daemon=True).start()
def callback_server(server_class=HTTPServer, handler_class=S, port=8080):
global httpd
httpd = server_class((localhost, 5003), handler_class)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment