/
do_openid_login.py
116 lines (85 loc) · 3.09 KB
/
do_openid_login.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/python
#
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 et sts=4 ai:
"""OpenID login page"""
# Python imports
# AppEngine Imports
from google.appengine.ext.webapp import template
# Our App imports
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
providers = {
'Google' : 'https://www.google.com/accounts/o8/id',
'Yahoo' : 'yahoo.com',
'MySpace' : 'myspace.com',
'AOL' : 'aol.com',
'MyOpenID' : 'myopenid.com'
# add more here
}
class MainHandler(webapp.RequestHandler):
def handle_openid(self, continue_url=None, openid_url=None):
if openid_url:
self.redirect(users.create_login_url(continue_url, None,
openid_url))
else:
self.response.out.write(template.render(
'templates/login.html', { 'google_url': users.create_login_url(federated_identity=providers.get('Google')) }))
def get(self):
continue_url = self.request.get('continue')
openid_url = self.request.get('openid_identifier')
self.handle_openid(continue_url, openid_url)
def post(self):
continue_url = self.request.get('continue')
openid_url = self.request.get('openid_identifier')
self.handle_openid(continue_url, openid_url)
application = webapp.WSGIApplication([
('.*', MainHandler),
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()
# #!/usr/bin/python
#
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 et sts=4 ai:
# """OpenID login page"""
# import config
# config.setup()
# # Python imports
# # AppEngine Imports
# from google.appengine.ext import webapp
# from google.appengine.ext.webapp import template
# # Our App imports
# from google.appengine.api import users
# from google.appengine.ext import webapp
# from google.appengine.ext.webapp.util import run_wsgi_app
# class MainHandler(webapp.RequestHandler):
# """Handles logins via AppEngine's integrated openid support."""
# def handle_openid(self, continue_url=None, openid_url=None):
# """If openid provided, being the dance; else return the login form."""
# if openid_url:
# self.redirect(users.create_login_url(continue_url, None,
# openid_url))
# else:
# self.response.out.write(template.render(
# 'templates/login.html', {'continue': continue_url}))
# def get(self):
# """Serve the login form."""
# continue_url = self.request.get('continue')
# openid_url = self.request.get('openid_identifier')
# self.handle_openid(continue_url, openid_url)
# def post(self):
# """Should have an endpoint now; start the dance"""
# continue_url = self.request.get('continue')
# openid_url = self.request.get('openid_identifier')
# self.handle_openid(continue_url, openid_url)
# application = webapp.WSGIApplication([
# ('.*', MainHandler),
# ], debug=True)
# def main():
# run_wsgi_app(application)
# if __name__ == '__main__':
# main()