Skip to content

Commit e987002

Browse files
Merge pull request #20 from yunojuno/django2
Drop support for Python2 and Django < 1.10
2 parents 9b7712a + 8168a55 commit e987002

30 files changed

+92
-111
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language:
22
python
33
python:
4-
- "2.7"
54
- "3.6"
65
addons:
76
postgresql: "9.4"

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Django app that uses JWT to manage one-time and expiring tokens to protect URLs.
1111

1212
This app currently requires the use of PostgreSQL.
1313

14+
Compatibility
15+
=============
16+
17+
This library is now Python3 and Django1.11 and above only. If you are on Python2 then you will have to refer to the python2 branch.
18+
1419
Background
1520
==========
1621

request_token/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# -*- coding: utf-8 -*-
21
default_app_config = 'request_token.apps.RequestTokenAppConfig'

request_token/admin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import json
32

43
from django.contrib import admin

request_token/apps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
from django.apps import AppConfig
32
from django.core.exceptions import ImproperlyConfigured
43
from django.template import loader, TemplateDoesNotExist

request_token/compat.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

request_token/decorators.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import functools
32
import logging
43

request_token/exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf8 -*-
21
"""
32
Local exceptions related to tokens inherit from the PyJWT base
43
InvalidTokenError.

request_token/middleware.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
# -*- coding: utf-8 -*-
21
import logging
32

43
from django.http import HttpResponseForbidden, HttpResponseNotAllowed
54
from django.template import loader
65

76
from jwt.exceptions import InvalidTokenError
87

9-
from .compat import MiddlewareMixin
108
from .models import RequestToken
119
from .settings import JWT_QUERYSTRING_ARG, FOUR03_TEMPLATE
1210
from .utils import decode
1311

1412
logger = logging.getLogger(__name__)
1513

1614

17-
class RequestTokenMiddleware(MiddlewareMixin):
15+
class RequestTokenMiddleware:
1816

1917
"""
2018
Extract and verify request tokens from incoming GET requests.
@@ -24,7 +22,10 @@ class RequestTokenMiddleware(MiddlewareMixin):
2422
2523
"""
2624

27-
def process_request(self, request):
25+
def __init__(self, get_response):
26+
self.get_response = get_response
27+
28+
def __call__(self, request):
2829
"""Verify JWT request querystring arg.
2930
3031
If a token is found (using JWT_QUERYSTRING_ARG), then it is decoded,
@@ -54,7 +55,7 @@ def process_request(self, request):
5455
token = request.GET.get(JWT_QUERYSTRING_ARG)
5556

5657
if token is None:
57-
return
58+
return self.get_response(request)
5859

5960
if request.method != 'GET':
6061
return HttpResponseNotAllowed(['GET'])
@@ -72,6 +73,8 @@ def process_request(self, request):
7273
request.token = None
7374
logger.exception("RequestToken cannot be decoded: %s", token)
7475

76+
return self.get_response(request)
77+
7578
def process_exception(self, request, exception):
7679
"""Handle all InvalidTokenErrors."""
7780
if isinstance(exception, InvalidTokenError):

request_token/migrations/0001_initial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Migration(migrations.Migration):
2323
('issued_at', models.DateTimeField(help_text='Time the token was created, set in the initial save.', null=True, blank=True)),
2424
('max_uses', models.IntegerField(default=1, help_text='Cap on the number of times the token can be used, defaults to 1 (single use).')),
2525
('used_to_date', models.IntegerField(default=0, help_text='Denormalised count of the number times the token has been used.')),
26-
('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, help_text='Intended recipient of the JWT.', null=True)),
26+
('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, help_text='Intended recipient of the JWT.', null=True, on_delete=models.deletion.CASCADE)),
2727
],
2828
),
2929
migrations.CreateModel(
@@ -33,8 +33,8 @@ class Migration(migrations.Migration):
3333
('user_agent', models.TextField(help_text='User-agent of client used to make the request.', blank=True)),
3434
('client_ip', models.CharField(help_text='Client IP of device used to make the request.', max_length=15)),
3535
('timestamp', models.DateTimeField(help_text='Time the request was logged.')),
36-
('token', models.ForeignKey(help_text='The RequestToken that was used.', to='request_token.RequestToken')),
37-
('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, help_text='The user who made the request (None if anonymous).', null=True)),
36+
('token', models.ForeignKey(help_text='The RequestToken that was used.', to='request_token.RequestToken', on_delete=models.deletion.CASCADE)),
37+
('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, help_text='The user who made the request (None if anonymous).', null=True, on_delete=models.deletion.CASCADE)),
3838
],
3939
),
4040
]

0 commit comments

Comments
 (0)