Skip to content

Commit

Permalink
Using Content-Type following spec and adding oauth_signature
Browse files Browse the repository at this point in the history
This works on a better patch for #GH-12. It follows the spec definition and also
includes the signature when posting when header_auth is not used.
  • Loading branch information
maraujop committed Feb 21, 2012
1 parent 06c282c commit 39e37fd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions oauth_hook/hook.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import time
from datetime import datetime
import random
import urllib
from urlparse import urlparse, urlunparse, parse_qs, urlsplit, urlunsplit
Expand Down Expand Up @@ -67,7 +68,7 @@ def get_normalized_parameters(request):
This function is called by SignatureMethod subclass CustomSignatureMethod_HMAC_SHA1
"""
# You can pass a string as data. See issues #10 and #12
if isinstance(request.data, basestring):
if not request.headers['Content-Type'] == 'application/x-www-form-urlencoded':
data_and_params = request.params.copy()
else:
data_and_params = dict(request.data.items() + request.params.items())
Expand Down Expand Up @@ -181,24 +182,29 @@ def __call__(self, request):
request.oauth_params['oauth_verifier'] = self.token.verifier
request.oauth_params['oauth_signature_method'] = self.signature.name

if 'oauth_callback' in request.data:
request.oauth_params['oauth_callback'] = request.data.pop('oauth_callback')
if 'oauth_callback' in request.params:
request.oauth_params['oauth_callback'] = request.params.pop('oauth_callback')

request.data_and_params = request.oauth_params.copy()
request.oauth_params['oauth_signature'] = self.signature.sign(request, self.consumer, self.token)
request.data_and_params['oauth_signature'] = request.oauth_params['oauth_signature']

if request.method in ("GET", "DELETE"):
if not self.header_auth:
request.data_and_params['oauth_signature'] = request.oauth_params['oauth_signature']
request.url = self.to_url(request)
else:
request.headers['Authorization'] = self.authorization_header(request.oauth_params)
else:
if not self.header_auth:
# You can pass a string as data. See issues #10 and #12
if isinstance(request.data, basestring):
if not request.headers['Content-Type'] == 'application/x-www-form-urlencoded':
request.url = self.to_url(request)
else:
request.data_and_params['oauth_signature'] = request.oauth_params['oauth_signature']
request._enc_data = self.to_postdata(request)
else:
request._enc_data = ""
request.headers['Authorization'] = self.authorization_header(request.oauth_params)

return request

0 comments on commit 39e37fd

Please sign in to comment.