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
from django.apps import AppConfig | |
class TestappConfig(AppConfig): | |
default_auto_field = 'django.db.models.BigAutoField' | |
name = 'testapp' | |
def ready(self): | |
import djwto.tokens as tokens |
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
import requests | |
sess = requests.Session() | |
sess.verify = False # For testing locally | |
sess.post('https://localhost:8002/login/', | |
data={'username': 'alice', 'password': 'pass'}) | |
sess.headers.update({'X-CSRFToken': sess.cookies['csrftoken']}) | |
r = sess.get('https://localhost:8002/protect/') |
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
# ./testapp/urls.py | |
from django.urls import path | |
from .views import ProtectedView, PermsProtectedView | |
urlpatterns = [ | |
path('protect/', ProtectedView.as_view(), name='protect'), | |
path('perms_protect/', PermsProtectedView.as_view(), name='perms_protect') | |
] |
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
# ./testapp/views.py | |
import djwto.authentication as auth # type: ignore | |
from django.views import View | |
from django.utils.decorators import method_decorator | |
from django.http.response import HttpResponse | |
class ProtectedView(View): | |
def dispatch(self, request, *args, **kwargs): | |
return super().dispatch(request, *args, **kwargs) |
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
import requests | |
sess = requests.Session() | |
sess.verify = False # For testing locally | |
r = sess.post('https://localhost:8002/login/', | |
data={'username': 'alice', 'password': 'pass'}) | |
sess.headers.update({'AUTHORIZATION': f'Bearer {r.json()["access"]}'}) |
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
import requests | |
sess = requests.Session() | |
sess.verify = False # For testing locally | |
r = sess.post('https://localhost:8002/login/', | |
data={'username': 'alice', 'password': 'pass'}) |
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
from django.contrib.auth import get_user_model | |
User = get_user_model() | |
user = User.objects.create_user('alice', '[email protected]', 'pass') | |
user.save() |
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
#./djwto_project/settings.py | |
(...) | |
DJWTO_SIGNING_KEY = os.environ['DJWTO_SIGNING_KEY'] | |
DJWTO_MODE = 'JSON' | |
DJWTO_REFRESH_COOKIE_PATH = 'api/token/refresh' | |
DJWTO_SAME_SITE = 'Lax' |