Mercurial > hg > bitsyauth
annotate example/example.py @ 27:b411066b4929
example/persona.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 26 Dec 2013 22:43:24 -0800 |
parents | 52713d176ab9 |
children |
rev | line source |
---|---|
16
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 def example_app(environ, start_response): |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 if environ['PATH_INFO'].strip('/') == 'authorization_required': |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 user = environ.get('REMOTE_USER') |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 if user: |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 start_response("200 OK", [('Content-Type', 'text/plain'), |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 ('Content-Length', str(len(user)))]) |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 return [user] |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 else: |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 text = '401 Unauthorized' |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 start_response("401 Unauthorized", [('Content-Type', 'text/plain'), |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 ('Content-Length', str(len(text)))]) |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 return [text] |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 text = """<html><body> |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 <a href="/authorization_required">bet you can't go here!</a> |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 </body></html>""" |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 start_response("200 OK", [('Content-Type', 'text/html'), |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 ('Content-Length', str(len(text)))]) |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 return [text] |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 if __name__ == '__main__': |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 from wsgiref import simple_server |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 server = simple_server.make_server('127.0.0.1', 12345, example_app) |
52713d176ab9
add an example....not done yet
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 server.serve_forever() |