def test_split_oauth(self): # OAuth headers are parsed correctly: see bug 314507. # This was really a bug in the underlying contrib/oauth.py module, but # it has no standalone test case. # # Note that the 'realm' parameter is not returned, because it's not # included in the OAuth calculations. headers = OAuthRequest._split_header( 'OAuth realm="foo", oauth_consumer_key="justtesting"') self.assertEquals(headers, {'oauth_consumer_key': 'justtesting'}) headers = OAuthRequest._split_header( 'OAuth oauth_consumer_key="justtesting"') self.assertEquals(headers, {'oauth_consumer_key': 'justtesting'}) headers = OAuthRequest._split_header( 'OAuth oauth_consumer_key="justtesting", realm="realm"') self.assertEquals(headers, {'oauth_consumer_key': 'justtesting'})
def get_oauth_authorization(request): """Retrieve OAuth authorization information from a request. The authorization information may be in the Authorization header, or it might be in the query string or entity-body. :return: a dictionary of authorization information. """ header = request._auth if header is not None and header.startswith("OAuth "): return OAuthRequest._split_header(header) else: return request.form
def get_oauth_authorization(request): """Retrieve OAuth authorization information from a request. The authorization information may be in the Authorization header, or it might be in the query string or entity-body. :return: a dictionary of authorization information. :raises UnicodeDecodeError: If the Authorization header is not valid UTF-8. """ header = request._auth if header is not None and header.startswith("OAuth "): # http://oauth.net/core/1.0/#encoding_parameters says "Text names # and values MUST be encoded as UTF-8 octets before percent-encoding # them", so we can reasonably fail if this hasn't been done. return OAuthRequest._split_header(six.ensure_text(header)) else: return request.form