Created
July 17, 2014 07:31
-
-
Save aniruddha-adhikary/e58fedf6501de01f93f8 to your computer and use it in GitHub Desktop.
Proxying callback server in Bottle.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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