diff options
| author | Chris Rossi <chris@archimedeanco.com> | 2012-10-14 14:17:00 -0400 |
|---|---|---|
| committer | Chris Rossi <chris@archimedeanco.com> | 2012-10-14 14:17:00 -0400 |
| commit | 0678dec16488928f23ea951d2d5ac44ddbc7935f (patch) | |
| tree | 00128b308b760d00359b1d0654cbb0ec26bdb2ac | |
| parent | 9937a4e2d4c575486c04b089141bfbd6325f3711 (diff) | |
| download | pyramid-0678dec16488928f23ea951d2d5ac44ddbc7935f.tar.gz pyramid-0678dec16488928f23ea951d2d5ac44ddbc7935f.tar.bz2 pyramid-0678dec16488928f23ea951d2d5ac44ddbc7935f.zip | |
Include recipe for issuing challenge.
| -rw-r--r-- | pyramid/authentication.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/pyramid/authentication.py b/pyramid/authentication.py index 7161e1d1f..50752c96e 100644 --- a/pyramid/authentication.py +++ b/pyramid/authentication.py @@ -826,7 +826,7 @@ class BasicAuthAuthenticationPolicy(CallbackAuthenticationPolicy): ``realm`` - Default: ``Realm``. The Basic Auth Realm string. Usually displayed to + Default: ``"Realm"``. The Basic Auth Realm string. Usually displayed to the user by the browser in the login dialog. ``debug`` @@ -836,6 +836,23 @@ class BasicAuthAuthenticationPolicy(CallbackAuthenticationPolicy): steps. The output from debugging is useful for reporting to maillist or IRC channels when asking for support. + **Issuing a challenge** + + Regular browsers will not send username/password credentials unless they + first receive a challenge from the server. The following recipe will + register a view that will send a Basic Auth challenge to the user whenever + there is an attempt to call a view which results in a Forbidden response:: + + from pyramid.httpexceptions import HTTPForbidden + from pyramid.httpexceptions import HTTPUnauthorized + from pyramid.security import forget + from pyramid.view import view_config + + @view_config(context=HTTPForbidden) + def basic_challenge(request): + response = HTTPUnauthorized() + response.headers.update(forget(request)) + return response """ def __init__(self, check, realm='Realm', debug=False): self.check = check |
