Skip to content

Commit

Permalink
Drop django 111 python27 add django 31 (#139)
Browse files Browse the repository at this point in the history
* Drop django-111, python-2.7 support, add django-31

* Remove old jwt package

* Update simple-jwt

* Disable simple-jwt tests on python3.6
  • Loading branch information
st4lk committed Jan 17, 2021
1 parent f8ee74b commit 1afb082
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 345 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,3 +27,4 @@ settings_local.py
.install-optional
.install-python-versions
venv/
.pyenv/
15 changes: 6 additions & 9 deletions .travis.yml
Expand Up @@ -2,30 +2,27 @@ language: python

matrix:
include:
- python: 2.7
env: TOXENV=py27-django111

- python: 3.5
env: TOXENV=py35-django111
- python: 3.5
env: TOXENV=py35-django22

- python: 3.6
env: TOXENV=py36-django111
- python: 3.6
env: TOXENV=py36-django22
- python: 3.6
env: TOXENV=py36-django30
- python: 3.6
env: TOXENV=py36-django31

- python: 3.7
env: TOXENV=py37-django111
- python: 3.7
env: TOXENV=py37-django22
- python: 3.7
env: TOXENV=py37-django30
- python: 3.7
env: TOXENV=py37-django31

- python: 3.8
env: TOXENV=py38-django30
- python: 3.8
env: TOXENV=py38-django31

install: pip install --quiet tox

Expand Down
17 changes: 9 additions & 8 deletions Makefile
@@ -1,6 +1,7 @@
.PHONY: run all test test_tox shell run-example native-test native-test-tox

PROJECT_PATH = /django_rest_social_auth
PROJECT_PATH_DOCKER = /django_rest_social_auth
PROJECT_PATH_NATIVE = "."
PORT ?= 8000

# ---------------------------
Expand All @@ -21,7 +22,7 @@ rebuild:
run: build
docker run -it --rm --name django-rest-social-auth \
-p $(PORT):$(PORT) \
-v $(PWD):$(PROJECT_PATH)/ \
-v $(PWD):$(PROJECT_PATH_DOCKER)/ \
st4lk/django-rest-social-auth "$(COMMAND)"

run-example:
Expand Down Expand Up @@ -77,12 +78,12 @@ native-lint: native-install-all

native-install-python-versions: .install-python-versions
.install-python-versions: tox.ini
curl https://pyenv.run | PYENV_ROOT=$(PROJECT_PATH)/.pyenv bash || echo '-- pyenv already setup, skipping --\n'
PYENV_ROOT=$(PROJECT_PATH)/.pyenv $(PROJECT_PATH)/.pyenv/bin/pyenv install -s 2.7.17
PYENV_ROOT=$(PROJECT_PATH)/.pyenv $(PROJECT_PATH)/.pyenv/bin/pyenv install -s 3.5.9
PYENV_ROOT=$(PROJECT_PATH)/.pyenv $(PROJECT_PATH)/.pyenv/bin/pyenv install -s 3.6.10
PYENV_ROOT=$(PROJECT_PATH)/.pyenv $(PROJECT_PATH)/.pyenv/bin/pyenv install -s 3.8.1
pyenv global system 2.7.17 3.5.9 3.6.10 3.8.1
curl https://pyenv.run | PYENV_ROOT=$(PROJECT_PATH_NATIVE)/.pyenv bash || echo '-- pyenv already setup, skipping --\n'
PYENV_ROOT=$(PROJECT_PATH_NATIVE)/.pyenv $(PROJECT_PATH_NATIVE)/.pyenv/bin/pyenv install -s 3.5.9
PYENV_ROOT=$(PROJECT_PATH_NATIVE)/.pyenv $(PROJECT_PATH_NATIVE)/.pyenv/bin/pyenv install -s 3.6.10
PYENV_ROOT=$(PROJECT_PATH_NATIVE)/.pyenv $(PROJECT_PATH_NATIVE)/.pyenv/bin/pyenv install -s 3.7.7
PYENV_ROOT=$(PROJECT_PATH_NATIVE)/.pyenv $(PROJECT_PATH_NATIVE)/.pyenv/bin/pyenv install -s 3.8.2
pyenv global system 3.5.9 3.6.10 3.7.7 3.8.2
touch $@

native-test-tox: native-install-python-versions native-clean
Expand Down
19 changes: 5 additions & 14 deletions README.md
Expand Up @@ -13,12 +13,12 @@ OAuth signin with django rest framework.
Requirements
-----------

- python (2.7, 3.5, 3.6, 3.7, 3.8)
- django (1.11, 2.2, 3.0)
- djangorestframework (>=3.1, <4.0)
- python (3.5, 3.6, 3.7, 3.8)
- django (2.2, 3.0, 3.1)
- djangorestframework (>=3.9, <4.0)
- social-auth-core (>=3.0, <4.0)
- social-auth-app-django (>=3.1, <4.0)
- [optional] djangorestframework-simplejwt (>=4.0.0)
- [optional] djangorestframework-simplejwt (>=4.4.0)
- [optional] django-rest-knox (>=4.0.0, <5.0.0)

Release notes
Expand Down Expand Up @@ -215,16 +215,7 @@ Quick start

Check [docs of simplejwt](https://github.com/davesque/django-rest-framework-simplejwt#token-types) for pair/sliding token difference.

Note: Since django-rest-framework-simplejwt doesn't support python 2.x, this APIs will work only with python 3.x.

5.3.1 jwt authentcation (using unmaintained [django-rest-framework-jwt](https://github.com/GetBlimp/django-rest-framework-jwt))

- POST /api/login/social/jwt/
- POST /api/login/social/jwt_user/

To use it, django-rest-framework-jwt must be installed.

Note: django-rest-framework-jwt package is not being maintained for a long time, therefore it is better to avoid using it. Current tool will drop support of it in next major version with high probability. But you may still want to use it if your project use python 2.7 or due to historical reasons.
Note. `django-rest-framework-simplejwt` doesn't work on and python3.6

5.4 knox authentication

Expand Down
10 changes: 2 additions & 8 deletions example_project/config/urls.py
@@ -1,4 +1,3 @@
import django
from django.conf.urls import include, url
from django.contrib import admin

Expand All @@ -9,24 +8,19 @@
url(r'^session/$', views.HomeSessionView.as_view(), name='home_session'),
url(r'^token/$', views.HomeTokenView.as_view(), name='home_token'),
url(r'^jwt/$', views.HomeJWTView.as_view(), name='home_jwt'),
url(r'^jwt-old/$', views.HomeJWTOldView.as_view(), name='home_jwt_old'),
url(r'^knox/$', views.HomeKnoxView.as_view(), name='home_knox'),

url(r'^api/login/', include('rest_social_auth.urls_session')),
url(r'^api/login/', include('rest_social_auth.urls_token')),
url(r'^api/login/', include('rest_social_auth.urls_jwt_pair')),
url(r'^api/login/', include('rest_social_auth.urls_jwt_sliding')),
url(r'^api/login/', include('rest_social_auth.urls_jwt')),
url(r'^api/login/', include('rest_social_auth.urls_knox')),

url(r'^api/logout/session/$', views.LogoutSessionView.as_view(), name='logout_session'),
url(r'^api/user/session/', views.UserSessionDetailView.as_view(), name="current_user_session"),
url(r'^api/user/token/', views.UserTokenDetailView.as_view(), name="current_user_token"),
url(r'^api/user/jwt/', views.UserJWTDetailView.as_view(), name="current_user_jwt"),
url(r'^api/user/jwt-old/', views.UserJWTOldDetailView.as_view(), name="current_user_jwt_old"),
url(r'^api/user/knox/', views.UserKnoxDetailView.as_view(), name="current_user_knox"),

url(r'^admin/', admin.site.urls),
]
if django.VERSION >= (2, 0, 0):
urlpatterns.append(url(r'^admin/', admin.site.urls))
else:
urlpatterns.append(url(r'^admin/', include(admin.site.urls)))
1 change: 0 additions & 1 deletion example_project/templates/base.html
Expand Up @@ -10,7 +10,6 @@ <h1>Django-rest-framework and OAuth example</h1>
<li><a href="{% url 'home_token' %}">Token auth</a></li>
<li><a href="{% url 'home_jwt' %}">JWT auth</a></li>
<li><a href="{% url 'home_knox' %}">Knox auth</a></li>
<li><a href="{% url 'home_jwt_old' %}">JWT old auth (deprecated)</a></li>
</ul>

{% block content %}
Expand Down
119 changes: 0 additions & 119 deletions example_project/templates/home_jwt_old.html

This file was deleted.

10 changes: 1 addition & 9 deletions example_project/users/views.py
Expand Up @@ -8,7 +8,7 @@
from rest_framework.response import Response
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from rest_social_auth.serializers import UserSerializer
from rest_social_auth.views import JWTAuthMixin, KnoxAuthMixin, SimpleJWTAuthMixin
from rest_social_auth.views import KnoxAuthMixin, SimpleJWTAuthMixin


class HomeSessionView(TemplateView):
Expand All @@ -27,10 +27,6 @@ class HomeJWTView(TemplateView):
template_name = 'home_jwt.html'


class HomeJWTOldView(TemplateView):
template_name = 'home_jwt_old.html'


class HomeKnoxView(TemplateView):
template_name = 'home_knox.html'

Expand Down Expand Up @@ -59,10 +55,6 @@ class UserTokenDetailView(BaseDetailView):
authentication_classes = (TokenAuthentication, )


class UserJWTOldDetailView(JWTAuthMixin, BaseDetailView):
pass


class UserJWTDetailView(SimpleJWTAuthMixin, BaseDetailView):
pass

Expand Down
3 changes: 1 addition & 2 deletions requirements_optional.txt
@@ -1,3 +1,2 @@
django-rest-knox>=4.0.0,<5.0.0
djangorestframework-simplejwt>=4.0.0
djangorestframework-jwt==1.11.0
djangorestframework-simplejwt>=4.4.0
3 changes: 1 addition & 2 deletions requirements_test.txt
@@ -1,6 +1,5 @@
pytest-django==3.4.8
pytest-django==4.1.0
httpretty==0.9.6
unittest2==1.0.1
mock==1.3.0
django-sslserver>=0.20
flake8==3.7.9
36 changes: 0 additions & 36 deletions rest_social_auth/serializers.py
Expand Up @@ -133,39 +133,3 @@ def get_token_payload(self, user):
payload = dict(UserSerializer(user).data)
payload.pop('id', None)
return payload


# Depcreated Seraizlisers
class JWTSerializer(TokenSerializer):

def get_token(self, obj):
warnings.warn(
'Support of djangorestframework-jwt will be removed in 3.0.0 version. '
'Use rest_framework_simplejwt instead.',
DeprecationWarning,
)
try:
from rest_framework_jwt.settings import api_settings
except ImportError:
warnings.warn('djangorestframework-jwt must be installed for JWT authentication',
ImportWarning)
raise

jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER

payload = jwt_payload_handler(self.get_jwt_payload(obj))
token = jwt_encode_handler(payload)

return token

def get_jwt_payload(self, obj):
"""
Define here, what data shall be encoded in JWT.
By default, entire object will be encoded.
"""
return obj


class UserJWTSerializer(JWTSerializer, UserSerializer):
pass
15 changes: 0 additions & 15 deletions rest_social_auth/urls_jwt.py

This file was deleted.

0 comments on commit 1afb082

Please sign in to comment.