-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
52 lines (45 loc) · 1.42 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import web
import urllib
import json
urls = ('/', 'index')
app = web.application(urls, globals())
render = web.template.render('templates/', base='base')
class FalseStorage(web.storage):
def __nonzero__(self): return False
def browserid():
# get user cookies:
c = web.cookies()
# if we find a browserid cookie:
if c.get('browserid_assertion'):
out = urllib.urlencode(dict(audience=web.ctx.host,
assertion=c.browserid_assertion))
# send it to browserid.org to verify it:
o = json.loads(urllib.urlopen('https://verifier.login.persona.org/verify', out).read())
if o['status'] == 'failure':
return FalseStorage(o)
else:
# if successful return the info:
return web.storage(o)
else:
return web.storage()
def auth():
# get authorization info from browserid:
bid = browserid()
# print the info for debugging:
print "This is what browserid returns: ", bid
# if we get a response, relay the information:
if bid:
response = "authorized as %s" % (bid['email'])
return response
else:
response = "unauthorized!"
return response
# render the main page
class index:
def GET(self):
# authenticate user:
userstatus = auth()
# render the main page with authentication info:
return render.index(userstatus)
if __name__ == '__main__':
app.run()