From e86396d524613bf1f0c238d1b458ed2ecf006f09 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 2 Sep 2014 10:50:43 -0400 Subject: [PATCH] Refactor required authentication info check The client_secret is unnecessary for RSA-based authentication, so don't require it. --- flask_oauthlib/client.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index e40042a2..50a1b931 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -231,11 +231,6 @@ def __init__( self.oauth = oauth self.name = name - if (not consumer_key or not consumer_secret) and not app_key: - raise TypeError( - 'OAuthRemoteApp requires consumer key and secret' - ) - self._base_url = base_url self._request_token_url = request_token_url self._access_token_url = access_token_url @@ -251,6 +246,26 @@ def __init__( self.app_key = app_key self.encoding = encoding + # Check for required authentication information. + # Skip this check if app_key is specified, since the information is + # specified in the Flask config, instead. + if not app_key: + req_params = self.request_token_params or {} + if req_params.get("signature_method") == oauthlib.oauth1.SIGNATURE_RSA: + # check for consumer_key and rsa_key + rsa_key = req_params.get("rsa_key") + if not consumer_key or not rsa_key: + raise TypeError( + "OAuthRemoteApp with RSA authentication requires " + "consumer key and rsa key" + ) + else: + # check for consumer_key and consumer_secret + if not consumer_key or not consumer_secret: + raise TypeError( + "OAuthRemoteApp requires consumer key and secret" + ) + @cached_property def base_url(self): return self._get_property('base_url') @@ -321,7 +336,8 @@ def make_client(self, token=None): params["resource_owner_secret"] = token[1] client = oauthlib.oauth1.Client( - self.consumer_key, self.consumer_secret, + client_key=self.consumer_key, + client_secret=self.consumer_secret, **params )