def on_request(self, request): if not self.on_path(request): return params = {} form = False parsed_url = request.parsed_url if request.body and request.body is not None: ctype = request.headers.iget('content-type') if ctype is not None and \ ctype.startswith('application/x-www-form-urlencoded'): # we are in a form try to get oauth params from here form = True params = dict(parse_qsl(request.body)) # update params from quey parameters params.update(parse_qsl(parsed_url.query)) raw_url = urlunparse((parsed_url.scheme, parsed_url.netloc, parsed_url.path, '', '', '')) oauth_req = Request.from_consumer_and_token(self.consumer, token=self.token, http_method=request.method, http_url=raw_url, parameters=params, is_form_encoded=form) oauth_req.sign_request(self.method, self.consumer, self.token) if form: request.body = oauth_req.to_postdata() request.headers['Content-Length'] = len(request.body) elif request.method in ('GET', 'HEAD'): request.original_url = request.url request.url = oauth_req.to_url() else: oauth_headers = oauth_req.to_header(realm=self.realm) request.headers.update(oauth_headers)
def on_request(self, request): if not self.on_path(request): return params = {} form = False parsed_url = request.parsed_url if request.body and request.body is not None: ctype = request.headers.iget('content-type') if ctype is not None and \ ctype.startswith('application/x-www-form-urlencoded'): # we are in a form try to get oauth params from here form = True params = dict(parse_qsl(request.body)) # update params from quey parameters params.update(parse_qsl(parsed_url.query)) raw_url = urlunparse((parsed_url.scheme, parsed_url.netloc, parsed_url.path, '', '', '')) oauth_req = Request.from_consumer_and_token(self.consumer, token=self.token, http_method=request.method, http_url=raw_url, parameters=params) oauth_req.sign_request(self.method, self.consumer, self.token) if form: request.body = oauth_req.to_postdata() request.headers['Content-Length'] = len(request.body) elif request.method in ('GET', 'HEAD'): request.original_url = request.url request.url = oauth_req.to_url() else: oauth_headers = oauth_req.to_header() request.headers.update(oauth_headers) print request.headers
def on_request(self, req): resource = self.on_path(req) if not resource: return consumer, token, method = resource headers = dict(req.headers) params = {} form = False if req.body and req.body is not None: ctype = headers.get('Content-Type') if ctype is not None and \ ctype.startswith('application/x-www-form-urlencoded'): # we are in a form try to get oauth params from here form = True params = dict(parse_qsl(req.body)) # update params from quey parameters params.update(parse_qsl(req.uri.query)) oauth_req = Request.from_consumer_and_token(consumer, token=token, http_method=req.method, http_url=req.url, parameters=params) oauth_req.sign_request(method, consumer, token) if form: req.body = oauth_req.to_postdata() elif req.method in ('GET', 'HEAD'): req.url = req.final_url = oauth_req.to_url() req.uri = urlparse.urlparse(req.url) else: oauth_headers = oauth_req.to_header() for k, v in list(oauth_headers.items()): if not isinstance(v, basestring): v = str(v) req.headers.append((k.title(), v))