All Articles

Very simple webserver for callback authentication in python

Every time i want to use an api with oAuth for experimenting and playing around i run into the same problem: I would have to create an server application to receive the token, to complete the login process.

That’s especially difficult if i want to use it in one of my ipython notebooks. But i found a really simple, but of course insecure solution. That’s why you should only use it for testing or playing around purposes.

I use WSGI with a really simple CGI interface. Like here:

from wsgiref.simple_server import make_server
from cgi import parse_qs, escape

def show_get_params(environ, start_response):
    subject = parse_qs(environ.get('QUERY_STRING', ''))
    start_response('200 OK', [('Content-Type', 'text/html')])
    return ['''%(subject)s''' % {'subject': subject}]

srv = make_server('localhost', 3000, show_get_params)

This code will start a server on port 3000 and will output all get parameters.

Published 16 Jul 2016

Writing about full stack development with python, react and testing with selenium.
Sven Schannak on Twitter