Commit 1d8ef5fd authored by Henrique Luiz Hartmann's avatar Henrique Luiz Hartmann Committed by Yuri H. Salvador

Implementar Autenticação

parent 5e8e8669
......@@ -3,8 +3,8 @@ from rest_framework_mongoengine import routers
from eventos.core.views import CertifiedViewSet, EventViewSet, SubmissionViewSet, TrackViewSet, UserViewSet
router = routers.SimpleRouter()
router.register("user", UserViewSet)
router.register("event", EventViewSet)
router.register("submission", SubmissionViewSet)
router.register("certified", CertifiedViewSet)
router.register("track", TrackViewSet)
router.register("users", UserViewSet, basename="user")
router.register("events", EventViewSet, basename="event")
router.register("submissions", SubmissionViewSet, basename="submission")
router.register("certifieds", CertifiedViewSet, basename="certified")
router.register("tracks", TrackViewSet, basename="track")
import os
from datetime import timedelta
import mongoengine
......@@ -26,6 +27,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
......@@ -53,7 +55,7 @@ TEMPLATES = [
WSGI_APPLICATION = "eventos.wsgi.application"
DATABASES = {"default": {"ENGINE": "", "NAME": ""}}
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": os.path.join(BASE_DIR, "db.sqlite3")}}
MONGO_USER = "root"
......@@ -74,6 +76,15 @@ AUTH_PASSWORD_VALIDATORS = [
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
LOGIN_URL = "/api/v1/sigin"
SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=60),
"REFRESH_TOKEN_LIFETIME": timedelta(days=2),
}
CORS_ORIGIN_WHITELIST = ["http://localhost:3000", "http://127.0.0.1:3000"]
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
......@@ -85,5 +96,10 @@ USE_L10N = True
USE_TZ = True
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
REST_FRAMEWORK = {"DEFAULT_RENDERER_CLASSES": ["rest_framework.renderers.JSONRenderer"]}
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": ["rest_framework_simplejwt.authentication.JWTAuthentication"],
"DEFAULT_RENDERER_CLASSES": ["rest_framework.renderers.JSONRenderer"],
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
}
......@@ -2,13 +2,16 @@ from django.contrib import admin
from django.urls import include, path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
from eventos.core.router import router as core_router
schema_view = get_schema_view(openapi.Info(title="Eventos", default_version="v1"), public=True)
urlpatterns = [
path("", include(core_router.urls)),
path("admin/", admin.site.urls),
path("swagger/", schema_view.with_ui()),
path("api/", include(core_router.urls)),
path("api/swagger/", schema_view.with_ui()),
path("api/token/", TokenObtainPairView.as_view(), name="token"),
path("api/refresh_token/", TokenRefreshView.as_view(), name="refresh_token"),
]
......@@ -141,6 +141,17 @@ sqlparse = ">=0.2.2"
argon2 = ["argon2-cffi (>=16.1.0)"]
bcrypt = ["bcrypt"]
[[package]]
category = "main"
description = "django-cors-headers is a Django application for handling the server headers required for Cross-Origin Resource Sharing (CORS)."
name = "django-cors-headers"
optional = false
python-versions = ">=3.5"
version = "3.4.0"
[package.dependencies]
Django = ">=2.0"
[[package]]
category = "main"
description = "MongoEngine support for Django Rest Framework."
......@@ -160,6 +171,26 @@ version = "3.11.0"
[package.dependencies]
django = ">=1.11"
[[package]]
category = "main"
description = "A minimal JSON Web Token authentication plugin for Django REST Framework"
name = "djangorestframework-simplejwt"
optional = false
python-versions = ">=3.6,<3.9"
version = "4.4.0"
[package.dependencies]
django = "*"
djangorestframework = "*"
pyjwt = "*"
[package.extras]
dev = ["bumpversion (>=0.5.3,<1)", "pytest-watch", "wheel", "twine", "ipython", "cryptography", "pytest-cov", "pytest-django", "pytest-xdist", "pytest", "tox", "flake8", "pep8", "isort", "Sphinx (>=1.6.5,<2)", "sphinx-rtd-theme (>=0.1.9)", "python-jose (3.0.0)"]
doc = ["Sphinx (>=1.6.5,<2)", "sphinx-rtd-theme (>=0.1.9)"]
lint = ["flake8", "pep8", "isort"]
python-jose = ["python-jose (3.0.0)"]
test = ["cryptography", "pytest-cov", "pytest-django", "pytest-xdist", "pytest", "tox"]
[[package]]
category = "main"
description = "Automated generation of real Swagger/OpenAPI 2.0 schemas from Django Rest Framework code."
......@@ -383,6 +414,19 @@ optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "2.1.1"
[[package]]
category = "main"
description = "JSON Web Token implementation in Python"
name = "pyjwt"
optional = false
python-versions = "*"
version = "1.7.1"
[package.extras]
crypto = ["cryptography (>=1.4)"]
flake8 = ["flake8", "flake8-import-order", "pep8-naming"]
test = ["pytest (>=4.0.1,<5.0.0)", "pytest-cov (>=2.6.0,<3.0.0)", "pytest-runner (>=4.2,<5.0.0)"]
[[package]]
category = "main"
description = "Python driver for MongoDB <http://www.mongodb.org>"
......@@ -564,8 +608,8 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"]
testing = ["jaraco.itertools", "func-timeout"]
[metadata]
content-hash = "1b817970f03c21ab272246146ae21fa1f8cb2ae06177ebd6afa5dfdf75a74a2d"
python-versions = "^3.7"
content-hash = "d30955c15b627dfde3c7d18ec3cbb08df51eed2f7929abe0a1fac40523534382"
python-versions = "^3.7, <3.9"
[metadata.files]
appdirs = [
......@@ -618,6 +662,10 @@ django = [
{file = "Django-3.0.5-py3-none-any.whl", hash = "sha256:642d8eceab321ca743ae71e0f985ff8fdca59f07aab3a9fb362c617d23e33a76"},
{file = "Django-3.0.5.tar.gz", hash = "sha256:d4666c2edefa38c5ede0ec1655424c56dc47ceb04b6d8d62a7eac09db89545c1"},
]
django-cors-headers = [
{file = "django-cors-headers-3.4.0.tar.gz", hash = "sha256:f5218f2f0bb1210563ff87687afbf10786e080d8494a248e705507ebd92d7153"},
{file = "django_cors_headers-3.4.0-py3-none-any.whl", hash = "sha256:5240062ef0b16668ce8a5f43324c388d65f5439e1a30e22c38684d5ddaff0d15"},
]
django-rest-framework-mongoengine = [
{file = "django-rest-framework-mongoengine-3.4.1.tar.gz", hash = "sha256:cabb60f2b8ecf6ceaa13550b47dde0b8f2fe9b6f7b69be681e059cf31b51d729"},
]
......@@ -625,6 +673,10 @@ djangorestframework = [
{file = "djangorestframework-3.11.0-py3-none-any.whl", hash = "sha256:05809fc66e1c997fd9a32ea5730d9f4ba28b109b9da71fccfa5ff241201fd0a4"},
{file = "djangorestframework-3.11.0.tar.gz", hash = "sha256:e782087823c47a26826ee5b6fa0c542968219263fb3976ec3c31edab23a4001f"},
]
djangorestframework-simplejwt = [
{file = "djangorestframework_simplejwt-4.4.0-py3-none-any.whl", hash = "sha256:288ee78618d906f26abf6282b639b8f1806ce1d9a7578897a125cf79c609f259"},
{file = "djangorestframework_simplejwt-4.4.0.tar.gz", hash = "sha256:c315be70aa12a5f5790c0ab9acd426c3a58eebea65a77d0893248c5144a5080c"},
]
drf-yasg = [
{file = "drf-yasg-1.17.1.tar.gz", hash = "sha256:5572e9d5baab9f6b49318169df9789f7399d0e3c7bdac8fdb8dfccf1d5d2b1ca"},
{file = "drf_yasg-1.17.1-py2.py3-none-any.whl", hash = "sha256:7d7af27ad16e18507e9392b2afd6b218fbffc432ec8dbea053099a2241e184ff"},
......@@ -735,6 +787,10 @@ pyflakes = [
{file = "pyflakes-2.1.1-py2.py3-none-any.whl", hash = "sha256:17dbeb2e3f4d772725c777fabc446d5634d1038f234e77343108ce445ea69ce0"},
{file = "pyflakes-2.1.1.tar.gz", hash = "sha256:d976835886f8c5b31d47970ed689944a0262b5f3afa00a5a7b4dc81e5449f8a2"},
]
pyjwt = [
{file = "PyJWT-1.7.1-py2.py3-none-any.whl", hash = "sha256:5c6eca3c2940464d106b99ba83b00c6add741c9becaec087fb7ccdefea71350e"},
{file = "PyJWT-1.7.1.tar.gz", hash = "sha256:8d59a976fb773f3e6a39c85636357c4f0e242707394cadadd9814f5cbaa20e96"},
]
pymongo = [
{file = "pymongo-3.10.1-cp27-cp27m-macosx_10_14_intel.whl", hash = "sha256:a732838c78554c1257ff2492f5c8c4c7312d0aecd7f732149e255f3749edd5ee"},
{file = "pymongo-3.10.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:358ba4693c01022d507b96a980ded855a32dbdccc3c9331d0667be5e967f30ed"},
......
......@@ -5,13 +5,15 @@ description = ""
authors = ["Henrique e Erick"]
[tool.poetry.dependencies]
python = "^3.7"
python = "^3.7, <3.9"
django = "^3.0.5"
django-rest-framework-mongoengine = "^3.4.1"
mongoengine = "^0.19.1"
djangorestframework = "^3.11.0"
blinker = "^1.4"
drf-yasg = "^1.17.1"
django-cors-headers = "^3.4.0"
djangorestframework-simplejwt = "^4.4.0"
[tool.poetry.dev-dependencies]
black = "^19.10b0"
......@@ -31,4 +33,3 @@ line_length = 119
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment