Skip to content

Commit d8efecb

Browse files
committed
Allow kwargs in OAuth2DecoratorFromClientSecrets.
This just extends `OAuth2Decorator`'s support for mapping additional kwargs to the subclass `OAuth2DecoratorFromClientSecrets`, and adds a test.
1 parent 7ced5c7 commit d8efecb

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

oauth2client/appengine.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,9 @@ def __init__(self, client_id, client_secret, scope,
665665
provided to this constructor. A string indicating the name of the field
666666
on the _credentials_class where a Credentials object will be stored.
667667
Defaults to 'credentials'.
668-
**kwargs: dict, Keyword arguments are be passed along as kwargs to the
669-
OAuth2WebServerFlow constructor.
668+
**kwargs: dict, Keyword arguments are passed along as kwargs to
669+
the OAuth2WebServerFlow constructor.
670+
670671
"""
671672
self._tls = threading.local()
672673
self.flow = None
@@ -923,7 +924,7 @@ def get(self):
923924
"""
924925

925926
@util.positional(3)
926-
def __init__(self, filename, scope, message=None, cache=None):
927+
def __init__(self, filename, scope, message=None, cache=None, **kwargs):
927928
"""Constructor
928929
929930
Args:
@@ -936,17 +937,20 @@ def __init__(self, filename, scope, message=None, cache=None):
936937
decorator.
937938
cache: An optional cache service client that implements get() and set()
938939
methods. See clientsecrets.loadfile() for details.
940+
**kwargs: dict, Keyword arguments are passed along as kwargs to
941+
the OAuth2WebServerFlow constructor.
939942
"""
940943
client_type, client_info = clientsecrets.loadfile(filename, cache=cache)
941944
if client_type not in [
942945
clientsecrets.TYPE_WEB, clientsecrets.TYPE_INSTALLED]:
943946
raise InvalidClientSecretsError(
944-
'OAuth2Decorator doesn\'t support this OAuth 2.0 flow.')
945-
constructor_kwargs = {
947+
"OAuth2Decorator doesn't support this OAuth 2.0 flow.")
948+
constructor_kwargs = dict(kwargs)
949+
constructor_kwargs.update({
946950
'auth_uri': client_info['auth_uri'],
947951
'token_uri': client_info['token_uri'],
948952
'message': message,
949-
}
953+
})
950954
revoke_uri = client_info.get('revoke_uri')
951955
if revoke_uri is not None:
952956
constructor_kwargs['revoke_uri'] = revoke_uri

tests/test_appengine.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
from oauth2client.appengine import FlowNDBProperty
6363
from oauth2client.appengine import FlowProperty
6464
from oauth2client.appengine import OAuth2Decorator
65+
from oauth2client.appengine import OAuth2DecoratorFromClientSecrets
6566
from oauth2client.appengine import StorageByKeyName
66-
from oauth2client.appengine import oauth2decorator_from_clientsecrets
6767
from oauth2client.client import AccessTokenRefreshError
6868
from oauth2client.client import Credentials
6969
from oauth2client.client import FlowExchangeError
@@ -748,7 +748,7 @@ def test_token_response_param(self):
748748
self.test_required()
749749

750750
def test_decorator_from_client_secrets(self):
751-
decorator = oauth2decorator_from_clientsecrets(
751+
decorator = OAuth2DecoratorFromClientSecrets(
752752
datafile('client_secrets.json'),
753753
scope=['foo_scope', 'bar_scope'])
754754
self._finish_setup(decorator, user_mock=UserMock)
@@ -765,16 +765,24 @@ def test_decorator_from_client_secrets(self):
765765
self.assertEqual(self.decorator._revoke_uri,
766766
self.decorator.credentials.revoke_uri)
767767

768+
def test_decorator_from_client_secrets_kwargs(self):
769+
decorator = OAuth2DecoratorFromClientSecrets(
770+
datafile('client_secrets.json'),
771+
scope=['foo_scope', 'bar_scope'],
772+
approval_prompt='force')
773+
self.assertTrue('approval_prompt' in decorator._kwargs)
774+
775+
768776
def test_decorator_from_cached_client_secrets(self):
769777
cache_mock = CacheMock()
770778
load_and_cache('client_secrets.json', 'secret', cache_mock)
771-
decorator = oauth2decorator_from_clientsecrets(
779+
decorator = OAuth2DecoratorFromClientSecrets(
772780
# filename, scope, message=None, cache=None
773781
'secret', '', cache=cache_mock)
774782
self.assertFalse(decorator._in_error)
775783

776784
def test_decorator_from_client_secrets_not_logged_in_required(self):
777-
decorator = oauth2decorator_from_clientsecrets(
785+
decorator = OAuth2DecoratorFromClientSecrets(
778786
datafile('client_secrets.json'),
779787
scope=['foo_scope', 'bar_scope'], message='NotLoggedInMessage')
780788
self.decorator = decorator
@@ -789,7 +797,7 @@ def test_decorator_from_client_secrets_not_logged_in_required(self):
789797
self.assertTrue('Login' in str(response))
790798

791799
def test_decorator_from_client_secrets_not_logged_in_aware(self):
792-
decorator = oauth2decorator_from_clientsecrets(
800+
decorator = OAuth2DecoratorFromClientSecrets(
793801
datafile('client_secrets.json'),
794802
scope=['foo_scope', 'bar_scope'], message='NotLoggedInMessage')
795803
self.decorator = decorator
@@ -804,7 +812,7 @@ def test_decorator_from_client_secrets_not_logged_in_aware(self):
804812
def test_decorator_from_unfilled_client_secrets_required(self):
805813
MESSAGE = 'File is missing'
806814
try:
807-
decorator = oauth2decorator_from_clientsecrets(
815+
decorator = OAuth2DecoratorFromClientSecrets(
808816
datafile('unfilled_client_secrets.json'),
809817
scope=['foo_scope', 'bar_scope'], message=MESSAGE)
810818
except InvalidClientSecretsError:
@@ -813,7 +821,7 @@ def test_decorator_from_unfilled_client_secrets_required(self):
813821
def test_decorator_from_unfilled_client_secrets_aware(self):
814822
MESSAGE = 'File is missing'
815823
try:
816-
decorator = oauth2decorator_from_clientsecrets(
824+
decorator = OAuth2DecoratorFromClientSecrets(
817825
datafile('unfilled_client_secrets.json'),
818826
scope=['foo_scope', 'bar_scope'], message=MESSAGE)
819827
except InvalidClientSecretsError:

0 commit comments

Comments
 (0)