summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIb Lundgren <ib.lundgren@gmail.com>2013-01-05 02:57:29 -0800
committerIb Lundgren <ib.lundgren@gmail.com>2013-01-05 02:57:29 -0800
commit3e62dd062b5ef03d268134bda7c49960e0d8ea25 (patch)
tree2840f403e1a4248811020bc9f91579b1288d0b5c
parent43124ab671f73e33a6a5f608dcb4afd997619a8f (diff)
parent6d562597e5c1c23743331b9682a5eb9a1c36afbc (diff)
downloadoauthlib-3e62dd062b5ef03d268134bda7c49960e0d8ea25.tar.gz
Merge pull request #87 from warsaw/issue86
Issue86
-rw-r--r--oauthlib/oauth1/rfc5849/__init__.py21
-rw-r--r--tests/oauth1/rfc5849/test_client.py22
2 files changed, 37 insertions, 6 deletions
diff --git a/oauthlib/oauth1/rfc5849/__init__.py b/oauthlib/oauth1/rfc5849/__init__.py
index f3dcd22..6099174 100644
--- a/oauthlib/oauth1/rfc5849/__init__.py
+++ b/oauthlib/oauth1/rfc5849/__init__.py
@@ -48,14 +48,15 @@ class Client(object):
signature_method=SIGNATURE_HMAC,
signature_type=SIGNATURE_TYPE_AUTH_HEADER,
rsa_key=None, verifier=None, realm=None,
- convert_to_unicode=False, encoding='utf-8'):
+ convert_to_unicode=False, encoding='utf-8',
+ nonce=None, timestamp=None):
if convert_to_unicode:
if isinstance(client_key, bytes_type):
client_key = client_key.decode(encoding)
if isinstance(client_secret, bytes_type):
client_secret = client_secret.decode(encoding)
- if isinstance(resource_owner, bytes_type):
- resource_owner = resource_owner.decode(encoding)
+ if isinstance(resource_owner_key, bytes_type):
+ resource_owner_key = resource_owner_key.decode(encoding)
if isinstance(resource_owner_secret, bytes_type):
resource_owner_secret = resource_owner_secret.decode(encoding)
if isinstance(callback_uri, bytes_type):
@@ -70,6 +71,10 @@ class Client(object):
verifier = verifier.decode(encoding)
if isinstance(realm, bytes_type):
realm = realm.decode(encoding)
+ if isinstance(nonce, bytes_type):
+ nonce = nonce.decode(encoding)
+ if isinstance(timestamp, bytes_type):
+ timestamp = timestamp.decode(encoding)
self.client_key = client_key
self.client_secret = client_secret
@@ -83,6 +88,8 @@ class Client(object):
self.realm = realm
self.convert_to_unicode = convert_to_unicode
self.encoding = encoding
+ self.nonce = nonce
+ self.timestamp = timestamp
if self.signature_method == SIGNATURE_RSA and self.rsa_key is None:
raise ValueError('rsa_key is required when using RSA signature method.')
@@ -128,9 +135,13 @@ class Client(object):
def get_oauth_params(self):
"""Get the basic OAuth parameters to be used in generating a signature.
"""
+ nonce = (generate_nonce()
+ if self.nonce is None else self.nonce)
+ timestamp = (generate_timestamp()
+ if self.timestamp is None else self.timestamp)
params = [
- ('oauth_nonce', generate_nonce()),
- ('oauth_timestamp', generate_timestamp()),
+ ('oauth_nonce', nonce),
+ ('oauth_timestamp', timestamp),
('oauth_version', '1.0'),
('oauth_signature_method', self.signature_method),
('oauth_consumer_key', self.client_key),
diff --git a/tests/oauth1/rfc5849/test_client.py b/tests/oauth1/rfc5849/test_client.py
index 5cc1f7e..c84ae5a 100644
--- a/tests/oauth1/rfc5849/test_client.py
+++ b/tests/oauth1/rfc5849/test_client.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
-from oauthlib.oauth1.rfc5849 import Client
+from oauthlib.oauth1.rfc5849 import Client, bytes_type
from ...unittest import TestCase
@@ -27,3 +27,23 @@ class ClientRealmTests(TestCase):
header["Authorization"].startswith('OAuth realm="baa-realm",'))
# make sure sign() does not override the default realm
self.assertEqual(client.realm, "moo-realm")
+
+
+class ClientConstructorTests(TestCase):
+
+ def test_convert_to_unicode_resource_owner(self):
+ client = Client('client-key',
+ resource_owner_key=b'owner key',
+ convert_to_unicode=True)
+ self.assertFalse(isinstance(client.resource_owner_key, bytes_type))
+ self.assertEqual(client.resource_owner_key, 'owner key')
+
+ def test_give_explicit_timestamp(self):
+ client = Client('client-key', timestamp='1')
+ params = dict(client.get_oauth_params())
+ self.assertEqual(params['oauth_timestamp'], '1')
+
+ def test_give_explicit_nonce(self):
+ client = Client('client-key', nonce='1')
+ params = dict(client.get_oauth_params())
+ self.assertEqual(params['oauth_nonce'], '1')