From cc4210dc555678b603e80da198f512bcc15b663b Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 30 Nov 2011 18:48:33 +0100 Subject: shrink AuthenticationMiddleware.authenticate interface The method no longer receives a start_response and is no longer responsible for calling self.app. Instead it returns a dictionary with the result of the authentication. --- wsgitools/digest.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'wsgitools/digest.py') diff --git a/wsgitools/digest.py b/wsgitools/digest.py index 628eac5..fc8e310 100644 --- a/wsgitools/digest.py +++ b/wsgitools/digest.py @@ -657,9 +657,7 @@ class AuthDigestMiddleware(AuthenticationMiddleware): assert hasattr(store, "checknonce") self.noncestore = store - def authenticate(self, auth, environ, start_response): - """wsgi interface""" - + def authenticate(self, auth, environ): try: credentials = parse_digest_response(auth) except ValueError: @@ -702,17 +700,14 @@ class AuthDigestMiddleware(AuthenticationMiddleware): if response is None or response != credresponse: raise AuthenticationRequired("wrong response") - environ["REMOTE_USER"] = credentials["username"] digest = dict(nextnonce=self.noncestore.newnonce()) if "qop" in credentials: digest["qop"] = "auth" digest["cnonce"] = credentials["cnonce"] # no KeyError digest["rspauth"] = self.auth_response(credentials, "") challenge = ", ".join(map('%s="%s"'.__mod__, digest.items())) - def modified_start_response(status, headers, exc_info=None): - headers.append(("Authentication-Info", challenge)) - return start_response(status, headers, exc_info) - return self.app(environ, modified_start_response) + return dict(user=credentials["username"], + outheaders=[("Authentication-Info", challenge)]) def auth_response(self, credentials, reqmethod): """internal method generating authentication tokens -- cgit v1.2.3