Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 70 lines (59 sloc) 1.87 KB
import cgi
import os
import requests
def print_login_form():
print """<html>
<script src=""></script>
function login() { (assertion) {
if (assertion) {
var assertion_field = document.getElementById("assertion-field");
assertion_field.value = assertion;
var login_form = document.getElementById("login-form");
<form id="login-form" method="POST">
<input id="assertion-field" type="hidden" name="assertion" value="">
<p><a href="javascript:login()">Login</a></p>
def verify_assertion(assertion):
audience = 'http://'
if 'HTTPS' in os.environ:
audience = 'https://'
audience += os.environ['SERVER_NAME'] + ':' + os.environ['SERVER_PORT']
page ='',
data={ "assertion": assertion,
"audience": audience})
data = page.json
except requests.exceptions.SSLError:
data = { "status": "failed",
"reason": "Could not verify SSL certificate" }
except requests.exceptions.ConnectionError:
data = { "status": "failed",
"reason": "Could not connect to server" }
return data
print 'Content-type: text/html\n\n'
form = cgi.FieldStorage()
if 'assertion' in form:
print "<html><body>"
result = verify_assertion(form['assertion'].value)
if result['status'] == 'okay':
print "<p>Logged in as: " + result['email'] + "</p>"
print "<p>Error: " + result['reason'] + "</p>"
print '<p><a href="python.cgi">Back to login page</p>'
print "</body></html>"
Jump to Line
Something went wrong with that request. Please try again.