Skip to content

Commit

Permalink
Merge pull request #154 from ahopkins/dev
Browse files Browse the repository at this point in the history
Version 1.3.0 - 2019-04-24
  • Loading branch information
ahopkins committed Apr 24, 2019
2 parents 432f0b5 + 8773d93 commit ec951d5
Show file tree
Hide file tree
Showing 56 changed files with 449 additions and 247 deletions.
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@

# General information about the project.
project = u"sanic-jwt"
copyright = u"2018, Adam Hopkins"
copyright = u"2019, Adam Hopkins"
author = u"Adam Hopkins"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u"1.2"
version = u"1.3"
# The full version, including alpha/beta/rc tags.
release = u"1.2.2"
release = u"1.3.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
10 changes: 10 additions & 0 deletions docs/source/pages/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Changelog

The format is based on `Keep a Changelog <http://keepachangelog.com/en/1.0.0/>`_ and this project adheres to `Semantic Versioning <http://semver.org/spec/v2.0.0.html>`_.

++++++++++++++++++++++++++
Version 1.3.0 - 2019-04-24
++++++++++++++++++++++++++

| **Added**
| - `#40 <https://github.com/ahopkins/sanic-jwt/issues/40>`_. Page redirection for static page protection
| - Support to be able to individually protect class-based view methods without the `decorators` property
|

++++++++++++++++++++++++++
Version 1.2.2 - 2019-03-14
++++++++++++++++++++++++++
Expand Down
8 changes: 8 additions & 0 deletions docs/source/pages/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ Alias for ``cookie_access_token_name``
| **Default**: ``60 * 3``, aka 3 minutes
|
----------
``login_redirect_url``
----------

| **Purpose**: Provide a default URL for authentication failure redirections on static pages.
| **Default**: ``/index.html``
|
------------------------
``path_to_authenticate``
------------------------
Expand Down
1 change: 0 additions & 1 deletion example/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class User:

def __init__(self, id, username, password):
self.user_id = id
self.username = username
Expand Down
17 changes: 10 additions & 7 deletions example/basic_with_certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class User:

def __init__(self, id, username, password):
self.user_id = id
self.username = username
Expand All @@ -23,12 +22,16 @@ def to_dict(self):
username_table = {u.username: u for u in users}
userid_table = {u.user_id: u for u in users}

public_key = Path(
__file__
).parent / ".." / "tests" / "resources" / "rsa-test-public.pem"
private_key = Path(
__file__
).parent / ".." / "tests" / "resources" / "rsa-test-key.pem"
public_key = (
Path(__file__).parent
/ ".."
/ "tests"
/ "resources"
/ "rsa-test-public.pem"
)
private_key = (
Path(__file__).parent / ".." / "tests" / "resources" / "rsa-test-key.pem"
)


async def authenticate(request, *args, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions example/cbv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class User:

def __init__(self, id, username, password):
self.user_id = id
self.username = username
Expand Down Expand Up @@ -48,7 +47,6 @@ async def authenticate(request, *args, **kwargs):


class PublicView(HTTPMethodView):

def get(self, request):
return json({"hello": "world"})

Expand Down
1 change: 0 additions & 1 deletion example/custom_authentication_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MyAuthentication(Authentication):

async def authenticate(self, request, *args, **kwargs):
username = request.json.get("username", None)
password = request.json.get("password", None)
Expand Down
1 change: 0 additions & 1 deletion example/custom_claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class User:

def __init__(self, id, username, password):
self.user_id = id
self.username = username
Expand Down
1 change: 0 additions & 1 deletion example/custom_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def retrieve_refresh_token(request, user_id, *args, **kwargs):


class Register(BaseEndpoint):

async def post(self, request, *args, **kwargs):
username = "username"
email = "email"
Expand Down
2 changes: 0 additions & 2 deletions example/extended_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class User:

def __init__(self, id, username, password):
self.user_id = id
self.username = username
Expand All @@ -25,7 +24,6 @@ def to_dict(self):


class MyAuthentication(Authentication):

async def extend_payload(self, payload, *args, **kwargs):
payload.update({"app_name": self.app.name})
return payload
Expand Down
1 change: 0 additions & 1 deletion example/extra_verifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class User:

def __init__(self, id, username, password):
self.user_id = id
self.username = username
Expand Down
1 change: 0 additions & 1 deletion example/inject_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class User:

def __init__(self, id, username, password):
self.user_id = id
self.username = username
Expand Down
1 change: 0 additions & 1 deletion example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ async def authenticate(request, *args, **kwargs):


class User:

def __init__(self, id, username, password):
setattr(self, "user_id", id)
self.username = username
Expand Down
1 change: 0 additions & 1 deletion example/scopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class User:

def __init__(self, id, username, password, scopes):
self.user_id = id
self.username = username
Expand Down
2 changes: 1 addition & 1 deletion sanic_jwt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.2.2"
__version__ = "1.3.0"
__author__ = "Adam Hopkins"
__credits__ = "Richard Kuesters"

Expand Down
14 changes: 8 additions & 6 deletions sanic_jwt/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


class BaseAuthentication:

def __init__(self, app, config):
self.app = app
self.claims = ["exp"]
Expand Down Expand Up @@ -115,7 +114,6 @@ async def retrieve_user(self, *args, **kwargs):


class Authentication(BaseAuthentication):

def _check_authentication(self, request, request_args, request_kwargs):
"""
Checks a request object to determine if that request contains a valid,
Expand Down Expand Up @@ -374,10 +372,14 @@ def _verify(
except jwt.exceptions.DecodeError as e:
self._reasons = e.args
# Make sure that the reasons all end with '.' for consistency
reason = [
x if x.endswith(".") else "{}.".format(x)
for x in list(e.args)
] if self.config.debug() else "Auth required."
reason = (
[
x if x.endswith(".") else "{}.".format(x)
for x in list(e.args)
]
if self.config.debug()
else "Auth required."
)
logger.debug(e.args)
is_valid = False
payload = None
Expand Down
1 change: 0 additions & 1 deletion sanic_jwt/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class BaseDerivative:

def __init__(self, config, instance, *args, **kwargs):
self.config = config
self.instance = instance
1 change: 0 additions & 1 deletion sanic_jwt/claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class Claim:

@classmethod
def _register(cls, sanicjwt):
required = ("key", "setup", "verify")
Expand Down
32 changes: 14 additions & 18 deletions sanic_jwt/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"expiration_delta": 60 * 5 * 6,
"generate_refresh_token": utils.generate_token,
"leeway": 60 * 3,
"login_redirect_url": "/index.html",
"path_to_authenticate": "/",
"path_to_refresh": "/refresh",
"path_to_retrieve_user": "/me",
Expand All @@ -50,11 +51,13 @@
"url_prefix": "/auth",
"user_id": "user_id",
"blueprint_name": "auth_bp",
"verify_exp": True
"verify_exp": True,
"login_redirect_url": None,
}

aliases = {
"cookie_access_token_name": "cookie_token_name", "secret": "public_key"
"cookie_access_token_name": "cookie_token_name",
"secret": "public_key",
}

ignore_keys = (
Expand Down Expand Up @@ -95,7 +98,6 @@ def _update_config_item(key, item_aliases, instance):


class ConfigItem:

def __init__(
self,
value,
Expand Down Expand Up @@ -150,7 +152,6 @@ def aliases(self):


class Configuration:

def __iter__(self): # noqa
for key in self.config_keys:
yield getattr(self, key)
Expand Down Expand Up @@ -181,9 +182,8 @@ def __new__(cls, *args, **kwargs):

# check if a configuration key is set
# and is an instance of ConfigItem
if (
hasattr(instance, key)
and isinstance(getattr(instance, key), ConfigItem)
if hasattr(instance, key) and isinstance(
getattr(instance, key), ConfigItem
):
_update_config_item(key, item_aliases, instance)
# check if a configuration key is set with a value
Expand Down Expand Up @@ -285,9 +285,8 @@ def _merge(self, key, value):

def _validate_secret(self):
logger.debug("validating provided secret")
if (
self.secret() is None
or (isinstance(self.secret(), str) and self.secret().strip() == "")
if self.secret() is None or (
isinstance(self.secret(), str) and self.secret().strip() == ""
):
raise exceptions.InvalidConfiguration(
"the SANIC_JWT_SECRET parameter cannot be None nor an empty "
Expand All @@ -296,14 +295,11 @@ def _validate_secret(self):

def _validate_keys(self):
logger.debug("validating keys (if needed)")
if (
utils.algorithm_is_asymmetric(self.algorithm())
and (
self.private_key() is None
or (
isinstance(self.private_key(), str)
and self.private_key().strip() == ""
)
if utils.algorithm_is_asymmetric(self.algorithm()) and (
self.private_key() is None
or (
isinstance(self.private_key(), str)
and self.private_key().strip() == ""
)
):
raise exceptions.RequiredKeysNotFound
Expand Down

0 comments on commit ec951d5

Please sign in to comment.