From 524ddd2bea510bea6c920fbe2c8b997ad75b1d97 Mon Sep 17 00:00:00 2001 From: earth2marsh Date: Fri, 5 Nov 2010 16:44:20 -0400 Subject: [PATCH 1/2] Enables requests to be signed for a provider and sent via a proxy. --- README.md | 4 ++-- oauth2/__init__.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3dca1e34..481b3d4b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Overview - -This code was originally forked from [Leah Culver and Andy Smith's oauth.py code](http://github.com/leah/python-oauth/). Some of the tests come from a [fork by Vic Fryzel](http://github.com/shellsage/python-oauth), while a revamped Request class and more tests were merged in from [Mark Paschal's fork](http://github.com/markpasc/python-oauth). A number of notable differences exist between this code and its forefathers: +This is a python implementation of OAuth 1.0a, extended to allow for sending signed requests through a proxy. +This code was forked from [SimpleGeo's python-oauth2](http://github.com/simplegeo/python-oauth2/), who forked from [Leah Culver and Andy Smith's oauth.py code](http://github.com/leah/python-oauth/). Some of the tests come from a [fork by Vic Fryzel](http://github.com/shellsage/python-oauth), while a revamped Request class and more tests were merged in from [Mark Paschal's fork](http://github.com/markpasc/python-oauth). A number of notable differences exist between this code and its forefathers: * 100% unit test coverage. * The DataStore object has been completely ripped out. While creating unit tests for the library I found several substantial bugs with the implementation and confirmed with Andy Smith that it was never fully baked. diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 65c3f071..c7c53bc3 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -537,7 +537,7 @@ def set_signature_method(self, method): self.method = method - def request(self, uri, method="GET", body=None, headers=None, + def request(self, uri, method="GET", proxy=None, body=None, headers=None, redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None): DEFAULT_CONTENT_TYPE = 'application/x-www-form-urlencoded' @@ -570,6 +570,9 @@ def request(self, uri, method="GET", body=None, headers=None, else: headers.update(req.to_header()) + if proxy: + uri = uri.replace(urlparse.urlparse(uri),proxy,1) + return httplib2.Http.request(self, uri, method=method, body=body, headers=headers, redirections=redirections, connection_type=connection_type) From 720c18bc98f2da24304e3a34cfe82ae48de23ea1 Mon Sep 17 00:00:00 2001 From: earth2marsh Date: Fri, 5 Nov 2010 17:08:44 -0400 Subject: [PATCH 2/2] updated examples with instructions for using a proxy --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 481b3d4b..86a90da2 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This code was forked from [SimpleGeo's python-oauth2](http://github.com/simplege # Set the API endpoint url = "http://example.com/photos" + PROXY_DOMAIN = "api-example.apigee.com" # Set the base oauth_* parameters along with any other parameters required # for the API call. @@ -61,6 +62,8 @@ The oauth2.Client is based on httplib2 and works just client = oauth.Client(consumer) # The OAuth Client request works just like httplib2 for the most part. + # Optional use with a proxy: + # resp, content = client.request(request_token_url, "GET", PROXY_DOMAIN) resp, content = client.request(request_token_url, "GET") print resp print content @@ -125,6 +128,8 @@ can be easily translated to a web application. token.set_verifier(oauth_verifier) client = oauth.Client(consumer, token) + # Optional use of a proxy: + # resp, content = client.request(access_token_url, "POST", PROXY_DOMAIN) resp, content = client.request(access_token_url, "POST") access_token = dict(urlparse.parse_qsl(content))