-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove custom token error handling (#49)
Token errors now raise a PermissionDenied error and are handled by Django.
- Loading branch information
1 parent
a43a79a
commit 09843d2
Showing
16 changed files
with
67 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "django-request-token" | ||
version = "0.13" | ||
version = "0.2.b0" | ||
description = "JWT-backed Django app for managing querystring tokens." | ||
license = "MIT" | ||
authors = ["YunoJuno <[email protected]>"] | ||
|
@@ -9,6 +9,7 @@ readme = "README.rst" | |
homepage = "https://github.com/yunojuno/django-request-token" | ||
repository = "https://github.com/yunojuno/django-request-token" | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Environment :: Web Environment", | ||
"Framework :: Django :: 2.2", | ||
"Framework :: Django :: 3.0", | ||
|
@@ -25,7 +26,6 @@ packages = [{ include = "request_token" }] | |
python = "^3.7" | ||
django = "^2.2 || ^3.0" | ||
pyjwt = "^2.0" | ||
sqlparse = "*" | ||
|
||
[tool.poetry.dev-dependencies] | ||
tox = "*" | ||
|
@@ -41,7 +41,7 @@ flake8-docstrings = "*" | |
isort = "*" | ||
mypy = "*" | ||
pre-commit = "*" | ||
black = "==19.10b0" | ||
black = { version="*", allow-prereleases=true } | ||
|
||
[build-system] | ||
requires = ["poetry>=0.12"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,10 @@ | ||
from __future__ import annotations | ||
|
||
from django.apps import AppConfig | ||
from django.core.exceptions import ImproperlyConfigured | ||
from django.template import TemplateDoesNotExist, loader | ||
|
||
from .settings import FOUR03_TEMPLATE | ||
|
||
|
||
class RequestTokenAppConfig(AppConfig): | ||
"""AppConfig for request_token app.""" | ||
|
||
name = "request_token" | ||
verbose_name = "JWT Request Tokens" | ||
|
||
def ready(self) -> None: | ||
"""Validate config and connect signals.""" | ||
super(RequestTokenAppConfig, self).ready() | ||
if FOUR03_TEMPLATE: | ||
check_template(FOUR03_TEMPLATE) | ||
|
||
|
||
def check_template(template: str) -> None: | ||
"""Check for the existance of the custom 403 page.""" | ||
try: | ||
loader.get_template(template) | ||
except TemplateDoesNotExist: | ||
raise ImproperlyConfigured( | ||
f"Custom request token template does not exist: '{template}'" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
request_token/migrations/0012_delete_requesttokenerrorlog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Generated by Django 3.1.7 on 2021-03-22 18:56 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("request_token", "0011_update_model_meta_options"), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name="RequestTokenErrorLog", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,9 @@ | ||
from os import getenv | ||
from typing import Any, Optional | ||
|
||
from django.conf import settings | ||
|
||
|
||
def _env_or_setting(key: str, default: Any) -> Any: | ||
return getenv(key) or getattr(settings, key, default) | ||
|
||
|
||
# the name of GET argument to contain the token | ||
JWT_QUERYSTRING_ARG = _env_or_setting("REQUEST_TOKEN_QUERYSTRING", "rt") # type: str | ||
JWT_QUERYSTRING_ARG: str = getattr(settings, "REQUEST_TOKEN_QUERYSTRING", "rt") | ||
|
||
# the fixed expiration check on Session tokens | ||
JWT_SESSION_TOKEN_EXPIRY = int(_env_or_setting("REQUEST_TOKEN_EXPIRY", 10)) # type: int | ||
|
||
# Set the default 403 template value | ||
FOUR03_TEMPLATE = _env_or_setting( | ||
"REQUEST_TOKEN_403_TEMPLATE", None | ||
) # type: Optional[str] | ||
|
||
# log all InvalidTokenErrors | ||
LOG_TOKEN_ERRORS = _env_or_setting( | ||
"REQUEST_TOKEN_LOG_TOKEN_ERRORS", "True" | ||
).lower() in ( | ||
"true", | ||
"1", | ||
) # noqa | ||
|
||
JWT_SESSION_TOKEN_EXPIRY: int = getattr(settings, "REQUEST_TOKEN_EXPIRY", 10) | ||
|
||
DEFAULT_MAX_USES = _env_or_setting("REQUEST_TOKEN_DEFAULT_MAX_USES", 10) | ||
DEFAULT_MAX_USES: int = getattr(settings, "REQUEST_TOKEN_DEFAULT_MAX_USES", 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.