Skip to content
Myr

Trim down OAuth1 callable logic

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Moved much of the validation out of requests and into oauthlib

authored by Idan Gazit · committed by Donald Stufft · parent 65bf3ab · Browse files · 1 file+10 added−27 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+10 added−27 removed

  • other:+10 added−27 removed

1 file+10 added−27 removed

modified:requests/auth.py+10 added-27 removed
9 unmodified lines
10import time11import hashlib1213from base64 import b64encode14from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_RSA,15 SIGNATURE_PLAINTEXT, SIGNATURE_TYPE_AUTH_HEADER, SIGNATURE_TYPE_QUERY,16 SIGNATURE_TYPE_BODY)14from oauthlib.oauth1.rfc5849 import (Client,15 SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER)16from oauthlib.common import extract_params17from .compat import urlparse, str18from .utils import randombytes, parse_dict_header1920CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'2122def _basic_auth_str(username, password):23 """Returns a Basic Auth string."""24
21 unmodified lines
46 resource_owner_secret, callback_uri, signature_method,47 signature_type, rsa_key, verifier)4849 def __call__(self, r):49 contenttype = r.headers.get('Content-Type')50 if (r.files or51 (contenttype and contenttype != 'application/x-www-form-urlencoded')):50 contenttype = r.headers.get('Content-Type', None)51 decoded_body = extract_params(r.data)52 if contenttype == None and decoded_body != None:53 r.headers['Content-Type'] = 'application/x-www-form-urlencoded'5453 # XXX TODO can we use body signatures with a non formencoded body?54 if self.client.signature_type == SIGNATURE_TYPE_BODY:55 raise ValueError('Body signatures may not be used with non-form-urlencoded content')5657 # Spec only specifies signing of application/x-www-form-urlencoded58 # params. Files don't get signed either.59 body = u''60 alter_body = False # we shouldn't touch the body61 else:62 body = r.data # OAuthLib is cool with both strings and dicts.63 if isinstance(body, str):64 # XXX gross hack. We must pass unicode...65 body = unicode(body, 'utf-8')66 alter_body = True6768 full_url, headers, new_body = self.client.sign(r.url, unicode(r.method), body, r.headers)6970 r.url = full_url71 if alter_body:72 r.data = new_body73 r.headers = headers55 r.url, r.headers, r.data = self.client.sign(56 unicode(r.url), unicode(r.method), r.data, r.headers)57 return r585960class HTTPBasicAuth(AuthBase):
118 unmodified lines