From 340f7a0733b6b023c2bec18bb0f91e8f1052a84d Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 23 Oct 2011 10:56:04 -0400 Subject: [PATCH] initial auth module w/ httpbasic auth --- requests/auth.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 requests/auth.py diff --git a/requests/auth.py b/requests/auth.py new file mode 100644 index 00000000..900a048f --- /dev/null +++ b/requests/auth.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +""" +requests.auth +~~~~~~~~~~~~~ + +This module contains the authentication handlers for Requests. +""" + +from base64 import encodestring as base64 + +def http_basic(r, username, password): + """Attaches HTTP Basic Authentication to the given Request object. + Arguments should be considered non-positional. + + """ + + auth_s = base64('%s:%s' % (username, password)).replace('\n', '') + r.headers['Authorization'] = ('Basic %s' % auth_s) + + return r + + +def http_digest(r, username, password): + """Attaches HTTP Digest Authentication to the given Request object. + Arguments should be considered non-positional. + """ + + r.headers \ No newline at end of file