From 3c1e9167ba6923429c57a7a8f3314d29ce3c90f3 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Mon, 6 Aug 2018 13:17:11 +0300 Subject: [PATCH 1/3] Add check to remove duplicate keyword arguments to _do_protection in decorators.py --- sanic_jwt/decorators.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sanic_jwt/decorators.py b/sanic_jwt/decorators.py index 9ea5723..0825622 100644 --- a/sanic_jwt/decorators.py +++ b/sanic_jwt/decorators.py @@ -126,6 +126,8 @@ async def decorated_function(request, *args, **kwargs): "f": f, } ) + if 'return_response' in protect_kwargs: + protect_kwargs.pop('protect_kwargs') _, instance = await _do_protection( return_response=False, *args, **protect_kwargs ) From 1de9e92b7b56f2ab183bb59556bbaaf2a79d255e Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Mon, 6 Aug 2018 13:45:17 +0300 Subject: [PATCH 2/3] Change to _do_protect method to overcome duplicate kwargs --- sanic_jwt/decorators.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/sanic_jwt/decorators.py b/sanic_jwt/decorators.py index 0825622..5d1df30 100644 --- a/sanic_jwt/decorators.py +++ b/sanic_jwt/decorators.py @@ -27,12 +27,16 @@ def instant_config(instance, **kwargs): clear_cache() -async def _do_protection(return_response=True, *args, **kwargs): +async def _do_protection(*args, **kwargs): initialized_on = kwargs.pop("initialized_on") kw = kwargs.pop("kw") request = kwargs.pop("request") f = kwargs.pop("f") + use_kwargs = deepcopy(kwargs) + if 'return_response' in use_kwargs: + use_kwargs.pop('return_response') + if initialized_on and isinstance(initialized_on, Blueprint): instance = initialized_on else: @@ -40,10 +44,10 @@ async def _do_protection(return_response=True, *args, **kwargs): with instant_config(instance, request=request, **kw): if request.method == "OPTIONS": - response = f(request, *args, **kwargs) + response = f(request, *args, **use_kwargs) if isawaitable(response): # noqa response = await response - if return_response: + if kwargs.get('return_response', True): return response else: @@ -53,7 +57,7 @@ async def _do_protection(return_response=True, *args, **kwargs): ( is_authenticated, status, reasons ) = instance.auth._check_authentication( - request, request_args=args, request_kwargs=kwargs + request, request_args=args, request_kwargs=use_kwargs ) except AttributeError: raise exceptions.SanicJWTException( @@ -71,8 +75,8 @@ async def _do_protection(return_response=True, *args, **kwargs): ) else e.args[0] if is_authenticated: - if return_response: - response = f(request, *args, **kwargs) + if kwargs.get('return_response', True): + response = f(request, *args, **use_kwargs) if isawaitable(response): response = await response return response @@ -124,12 +128,11 @@ async def decorated_function(request, *args, **kwargs): "kw": kw, "request": request, "f": f, + "return_response": False, } ) - if 'return_response' in protect_kwargs: - protect_kwargs.pop('protect_kwargs') _, instance = await _do_protection( - return_response=False, *args, **protect_kwargs + *args, **protect_kwargs ) if request.method == "OPTIONS": From 9a8deb48409e32ead03d593abd9ed9dec13f829c Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Mon, 6 Aug 2018 13:51:24 +0300 Subject: [PATCH 3/3] v1.1.4 changelog and bumpversion --- docs/source/conf.py | 2 +- docs/source/index.rst | 4 ++++ docs/source/pages/changelog.rst | 8 ++++++++ sanic_jwt/__init__.py | 2 +- setup.py | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index fd2553e..595143d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -56,7 +56,7 @@ # The short X.Y version. version = u"1.1" # The full version, including alpha/beta/rc tags. -release = u"1.1.3" +release = u"1.1.4" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/index.rst b/docs/source/index.rst index 5c288b5..cafa5bd 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -48,6 +48,10 @@ Flexibility is really the name of the game for v. 1.1. Most of the features are Checkout the changelog for a more detailed description. +.. note:: + + It is recommended that you are at least using **version 1.1.2**. You can upgrade to **version 1.1.4** for improved exception handling and some bug fixes. + +++++++++++++++++++++++++++ What is new in Version 1.0? +++++++++++++++++++++++++++ diff --git a/docs/source/pages/changelog.rst b/docs/source/pages/changelog.rst index a1956d8..935609f 100644 --- a/docs/source/pages/changelog.rst +++ b/docs/source/pages/changelog.rst @@ -4,6 +4,14 @@ Changelog The format is based on `Keep a Changelog `_ and this project adheres to `Semantic Versioning `_. +++++++++++++++++++++++++++ +Version 1.1.4 - 2018-08-06 +++++++++++++++++++++++++++ + +| **Fixed** +| - Bug with ``_do_protect`` in ``@scoped`` decorator +| + ++++++++++++++++++++++++++ Version 1.1.3 - 2018-08-06 ++++++++++++++++++++++++++ diff --git a/sanic_jwt/__init__.py b/sanic_jwt/__init__.py index a1564c3..a787e76 100644 --- a/sanic_jwt/__init__.py +++ b/sanic_jwt/__init__.py @@ -1,4 +1,4 @@ -__version__ = "1.1.3" +__version__ = "1.1.4" __author__ = "Adam Hopkins" __credits__ = "Richard Kuesters" diff --git a/setup.py b/setup.py index d69ca89..95857ec 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ setup( name="sanic-jwt", - version="1.1.3", + version="1.1.4", description="JWT oauth flow for Sanic", url="https://github.com/ahopkins/sanic-jwt", download_url="https://github.com/ahopkins/sanic-jwt/archive/master.zip",