Skip to content

Commit 40694ad

Browse files
committed
Autenticação
1 parent d8c00c4 commit 40694ad

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

Daily/settings.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212

1313
import os
14+
from datetime import timedelta
1415

1516
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1617
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -33,8 +34,28 @@
3334

3435
# SESSION_EXPIRE_AT_BROWSER_CLOSE = True
3536

36-
# Application definition
3737

38+
# REST Framework configs
39+
REST_FRAMEWORK = {
40+
'DEFAULT_PERMISSION_CLASSES': (
41+
'rest_framework.permissions.IsAuthenticated',
42+
),
43+
'DEFAULT_AUTHENTICATION_CLASSES': (
44+
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
45+
'rest_framework.authentication.SessionAuthentication',
46+
'rest_framework.authentication.BasicAuthentication',
47+
),
48+
'NON_FIELD_ERRORS_KEY': 'global',
49+
}
50+
51+
# JWT settings
52+
JWT_AUTH = {
53+
'JWT_ALLOW_REFRESH': True,
54+
'JWT_EXPIRATION_DELTA': timedelta(days=2),
55+
}
56+
57+
58+
# Application definition
3859

3960
INSTALLED_APPS = [
4061
'django.contrib.admin',

api/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from sys import path
2+
13
from django.conf.urls import url
4+
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
25
from Funcionarios.views import ProjetosListView, ProjetosIDView, AtividadesListView, AtividadesIDView, PerfilListView
36

47
urlpatterns = [
@@ -7,4 +10,6 @@
710
url(r'^api/perfis/$', PerfilListView.as_view(), name='perfis'),
811
url(r'^api/projetos/(?P<pk>[0-9]+)/$', ProjetosIDView.as_view(), name='projetos_id'),
912
url(r'^api/atividades/(?P<pk>[0-9]+)/$', AtividadesIDView.as_view(), name='atividades_id'),
13+
url('login/', obtain_jwt_token),
14+
url('refresh-token/', refresh_jwt_token),
1015
]

0 commit comments

Comments
 (0)