Performs digest authentication on the given HTTP request handler. Returns True if authentication was successful, False otherwise. If no users have been set, then digest auth is effectively disabled and this method will always return True.
(self, request_handler)
| 158 | return False |
| 159 | |
| 160 | def handle_request(self, request_handler): |
| 161 | """Performs digest authentication on the given HTTP request |
| 162 | handler. Returns True if authentication was successful, False |
| 163 | otherwise. |
| 164 | |
| 165 | If no users have been set, then digest auth is effectively |
| 166 | disabled and this method will always return True. |
| 167 | """ |
| 168 | |
| 169 | if len(self._users) == 0: |
| 170 | return True |
| 171 | |
| 172 | if "Proxy-Authorization" not in request_handler.headers: |
| 173 | return self._return_auth_challenge(request_handler) |
| 174 | else: |
| 175 | auth_dict = self._create_auth_dict( |
| 176 | request_handler.headers["Proxy-Authorization"] |
| 177 | ) |
| 178 | if auth_dict["username"] in self._users: |
| 179 | password = self._users[ auth_dict["username"] ] |
| 180 | else: |
| 181 | return self._return_auth_challenge(request_handler) |
| 182 | if not auth_dict.get("nonce") in self._nonces: |
| 183 | return self._return_auth_challenge(request_handler) |
| 184 | else: |
| 185 | self._nonces.remove(auth_dict["nonce"]) |
| 186 | |
| 187 | auth_validated = False |
| 188 | |
| 189 | # MSIE uses short_path in its validation, but Python's |
| 190 | # urllib.request uses the full path, so we're going to see if |
| 191 | # either of them works here. |
| 192 | |
| 193 | for path in [request_handler.path, request_handler.short_path]: |
| 194 | if self._validate_auth(auth_dict, |
| 195 | password, |
| 196 | request_handler.command, |
| 197 | path): |
| 198 | auth_validated = True |
| 199 | |
| 200 | if not auth_validated: |
| 201 | return self._return_auth_challenge(request_handler) |
| 202 | return True |
| 203 | |
| 204 | |
| 205 | class BasicAuthHandler(http.server.BaseHTTPRequestHandler): |
no test coverage detected