Created
January 27, 2011 20:35
-
-
Save mcdonc/799200 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from paste.httpserver import serve | |
from pyramid.view import view_config | |
from pyramid.response import Response | |
@view_config(route_name='login', request_method='GET') | |
@view_config(context='pyramid.exceptions.Forbidden') | |
def login(request): | |
return Response('Log In', status=401) | |
@view_config(route_name='protected', permission='nevergonnagetit') | |
def protected(request): | |
return Response('Oh you got it') | |
if __name__ == '__main__': | |
from pyramid.config import Configurator | |
from pyramid.authentication import AuthTktAuthenticationPolicy | |
c = Configurator(authentication_policy=AuthTktAuthenticationPolicy('w')) | |
c.add_route('login', '/login') | |
c.add_route('protected', '/protected') | |
c.scan('__main__') | |
serve(c.make_wsgi_app()) | |
# [chrism@thinko ~]$ curl -i http://127.0.0.1:8080/login | |
# HTTP/1.0 401 Unauthorized | |
# Server: PasteWSGIServer/0.5 Python/2.6.5 | |
# Date: Thu, 27 Jan 2011 20:34:25 GMT | |
# Content-Type: text/html; charset=UTF-8 | |
# Content-Length: 6 | |
# Log In[chrism@thinko ~]$ curl -i http://127.0.0.1:8080/protected | |
# HTTP/1.0 401 Unauthorized | |
# Server: PasteWSGIServer/0.5 Python/2.6.5 | |
# Date: Thu, 27 Jan 2011 20:34:28 GMT | |
# Content-Type: text/html; charset=UTF-8 | |
# Content-Length: 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment