Skip to content

Instantly share code, notes, and snippets.

@aniruddha-adhikary
Created July 17, 2014 07:31
Show Gist options
  • Save aniruddha-adhikary/e58fedf6501de01f93f8 to your computer and use it in GitHub Desktop.
Save aniruddha-adhikary/e58fedf6501de01f93f8 to your computer and use it in GitHub Desktop.
Proxying callback server in Bottle.py
#!/usr/bin/env python
from bottle import request, run, route, template, static_file
@route('/box/auth')
def authorize_box():
code = request.query.code;
if(code):
return template("""
<!doctype html>
<html>
<head>
<title>Authorizing...</title>
</head>
<body>
<script src="/box/iframe.js?code={{code}}"></script>
</body>
</html>
""", code=code)
@route('/box/iframe.js')
def iframejs():
code = request.query.code;
if(code):
return template("""
window.onload = function() {
var receiver = window.parent.window;
function sendMessage() {
receiver.postMessage("{{ code }}", '*');
}
sendMessage();
}
""", code=code)
@route('/static/<filename>')
def server_static(filename):
return static_file(filename, root='./static')
run(host='localhost', port=3000, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment