remove old auth stuff
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 377078b · Browse files · 1 file·+0 added−102 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+0 added−102 removed
- other:+0 added−102 removed
Provenance
- Commit
1c30ef4- Tree
56eab29- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
377078b
1 file changed+0 added−102 removed
modified:requests/auth.py-102 removed
6 unmodified lines7 This module contains the authentication handlers for Requests.8 """9 10 import os11-import re11 import time12 import hashlib13 import logging14 1 unmodified line16 17 from .compat import urlparse, str18 from .utils import parse_dict_header19 21-try:22- from oauthlib.common import extract_params23- from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER)20 25-except (ImportError, SyntaxError):26- SIGNATURE_HMAC = None27- SIGNATURE_TYPE_AUTH_HEADER = None28-29-try:30- import kerberos as k31-except ImportError as exc:32- k = None33-21 log = logging.getLogger(__name__)22 23 CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'24 CONTENT_TYPE_MULTI_PART = 'multipart/form-data'10 unmodified lines35 36 def __call__(self, r):37 raise NotImplementedError('Auth hooks must be callable.')38 52-53-class OAuth1(AuthBase):54- """Signs the request using OAuth 1 (RFC5849)"""55- def __init__(self, client_key,56- client_secret=None,57- resource_owner_key=None,58- resource_owner_secret=None,59- callback_uri=None,60- signature_method=SIGNATURE_HMAC,61- signature_type=SIGNATURE_TYPE_AUTH_HEADER,62- rsa_key=None, verifier=None):63-64- try:65- signature_type = signature_type.upper()66- except AttributeError:67- pass68-69- self.client = Client(client_key, client_secret, resource_owner_key,70- resource_owner_secret, callback_uri, signature_method,71- signature_type, rsa_key, verifier)72-73- def __call__(self, r):74- """Add OAuth parameters to the request.75-76- Parameters may be included from the body if the content-type is77- urlencoded, if no content type is set an educated guess is made.78- """79- # split(";") because Content-Type may be "multipart/form-data; boundary=xxxxx"80- contenttype = r.headers.get('Content-Type', '').split(";")[0].lower()81- # extract_params will not give params unless the body is a properly82- # formatted string, a dictionary or a list of 2-tuples.83- decoded_body = extract_params(r.data)84-85- # extract_params can only check the present r.data and does not know86- # of r.files, thus an extra check is performed. We know that87- # if files are present the request will not have88- # Content-type: x-www-form-urlencoded. We guess it will have89- # a mimetype of multipart/form-data and if this is not the case90- # we assume the correct header will be set later.91- _oauth_signed = True92- if r.files and contenttype == CONTENT_TYPE_MULTI_PART:93- # Omit body data in the signing and since it will always94- # be empty (cant add paras to body if multipart) and we wish95- # to preserve body.96- r.url, r.headers, _ = self.client.sign(unicode(r.full_url),97- unicode(r.method),98- None,99- r.headers)100- elif (decoded_body is not None and101- contenttype == CONTENT_TYPE_FORM_URLENCODED):102- # If the Content-Type header is urlencoded and there are no103- # illegal characters in the body, assume that the content actually104- # is urlencoded, and so should be part of the signature.105- r.url, r.headers, r.data = self.client.sign(unicode(r.full_url),106- unicode(r.method),107- r.data,108- r.headers)109- else:110- # The data we passed was either definitely not urlencoded111- # (because extract_params returned nothing) or doesn't have a112- # content header that assures us that it is. Assume then that the113- # data shouldn't be part of the signature.114- r.url, r.headers, _ = self.client.sign(unicode(r.full_url),115- unicode(r.method),116- None,117- r.headers)118- if _oauth_signed:119- # Both flows add params to the URL by using r.full_url,120- # so this prevents adding it again later121- r.params = {}122-123- # Having the authorization header, key or value, in unicode will124- # result in UnicodeDecodeErrors when the request is concatenated125- # by httplib. This can easily be seen when attaching files.126- # Note that simply encoding the value is not enough since Python127- # saves the type of first key set. Thus we remove and re-add.128- # >>> d = {u'a':u'foo'}129- # >>> d['a'] = 'foo'130- # >>> d131- # { u'a' : 'foo' }132- u_header = unicode('Authorization')133- if u_header in r.headers:134- auth_header = r.headers[u_header].encode('utf-8')135- del r.headers[u_header]136- r.headers['Authorization'] = auth_header137-138- return r139-140-39 class HTTPBasicAuth(AuthBase):40 """Attaches HTTP Basic Authentication to the given Request object."""41 def __init__(self, username, password):42 self.username = username128 unmodified lines