diff --git a/backend/rotini/auth/urls.py b/backend/rotini/auth/urls.py deleted file mode 100644 index 62e7ec0..0000000 --- a/backend/rotini/auth/urls.py +++ /dev/null @@ -1,9 +0,0 @@ -import django.urls -import auth.views - -urlpatterns = [ - django.urls.path( - "session/", auth.views.SessionListView.as_view(), name="auth-session-list" - ), - django.urls.path("user/", auth.views.UserListView.as_view(), name="auth-user-list"), -] diff --git a/backend/rotini/base/settings.py b/backend/rotini/base/settings.py index 0ebc4bb..b0a3466 100644 --- a/backend/rotini/base/settings.py +++ b/backend/rotini/base/settings.py @@ -31,6 +31,7 @@ INSTALLED_APPS = [ "rest_framework", "corsheaders", "files", + "identity", ] MIDDLEWARE = [ @@ -39,7 +40,7 @@ MIDDLEWARE = [ "corsheaders.middleware.CorsMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", - "auth.middleware.JwtMiddleware", + "identity.middleware.JwtMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", @@ -47,8 +48,8 @@ MIDDLEWARE = [ ROOT_URLCONF = "base.urls" -CORS_ALLOWED_ORIGINS = ["http://localhost:1234"] -CSRF_TRUSTED_ORIGINS = ["http://localhost:1234"] +CORS_ALLOWED_ORIGINS = ["https://localhost:1234"] +CSRF_TRUSTED_ORIGINS = ["https://localhost:1234"] TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", diff --git a/backend/rotini/base/urls.py b/backend/rotini/base/urls.py index 57706be..d51c5c7 100644 --- a/backend/rotini/base/urls.py +++ b/backend/rotini/base/urls.py @@ -18,10 +18,10 @@ from django.contrib import admin import django.urls as django_urls import files.urls as files_urls -import auth.urls +import identity.urls urlpatterns = [ django_urls.path("admin/", admin.site.urls), django_urls.path("", django_urls.include(files_urls.urlpatterns)), - django_urls.path("auth/", django_urls.include(auth.urls.urlpatterns)), + django_urls.path("auth/", django_urls.include(identity.urls.urlpatterns)), ] diff --git a/backend/rotini/auth/__init__.py b/backend/rotini/identity/__init__.py similarity index 100% rename from backend/rotini/auth/__init__.py rename to backend/rotini/identity/__init__.py diff --git a/backend/rotini/auth/apps.py b/backend/rotini/identity/apps.py similarity index 84% rename from backend/rotini/auth/apps.py rename to backend/rotini/identity/apps.py index 6a09aaa..b404d98 100644 --- a/backend/rotini/auth/apps.py +++ b/backend/rotini/identity/apps.py @@ -3,4 +3,4 @@ from django.apps import AppConfig class AuthConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" - name = "auth" + name = "identity" diff --git a/backend/rotini/auth/jwt.py b/backend/rotini/identity/jwt.py similarity index 100% rename from backend/rotini/auth/jwt.py rename to backend/rotini/identity/jwt.py diff --git a/backend/rotini/auth/jwt_test.py b/backend/rotini/identity/jwt_test.py similarity index 63% rename from backend/rotini/auth/jwt_test.py rename to backend/rotini/identity/jwt_test.py index f261ab7..44c39df 100644 --- a/backend/rotini/auth/jwt_test.py +++ b/backend/rotini/identity/jwt_test.py @@ -2,17 +2,17 @@ import pytest import freezegun import jwt -import auth.jwt +import identity.jwt @freezegun.freeze_time("2012-01-01") def test_generates_and_decodes_token_token(): MOCK_USER_ID = 1 - token = auth.jwt.generate_token_for_user(MOCK_USER_ID) + token = identity.jwt.generate_token_for_user(MOCK_USER_ID) assert token is not None - token_data = auth.jwt.decode_token(token) + token_data = identity.jwt.decode_token(token) assert token_data["user_id"] == MOCK_USER_ID @@ -21,9 +21,9 @@ def test_token_decode_fails_if_expired(): MOCK_USER_ID = 1 with freezegun.freeze_time("2012-01-01"): - token = auth.jwt.generate_token_for_user(MOCK_USER_ID) + token = identity.jwt.generate_token_for_user(MOCK_USER_ID) assert token is not None with pytest.raises(jwt.ExpiredSignatureError): - auth.jwt.decode_token(token) + identity.jwt.decode_token(token) diff --git a/backend/rotini/auth/middleware.py b/backend/rotini/identity/middleware.py similarity index 93% rename from backend/rotini/auth/middleware.py rename to backend/rotini/identity/middleware.py index c88ee96..647b570 100644 --- a/backend/rotini/auth/middleware.py +++ b/backend/rotini/identity/middleware.py @@ -3,7 +3,7 @@ import logging import django.http import django.contrib.auth -import auth.jwt +import identity.jwt logger = logging.getLogger(__name__) @@ -34,7 +34,7 @@ class JwtMiddleware: if jwt_cookie is not None: try: - decoded_token = auth.jwt.decode_token(jwt_cookie) + decoded_token = identity.jwt.decode_token(jwt_cookie) logger.info("Token: %s\nDecoded token: %s", jwt_cookie, decoded_token) diff --git a/backend/rotini/auth/middleware_test.py b/backend/rotini/identity/middleware_test.py similarity index 88% rename from backend/rotini/auth/middleware_test.py rename to backend/rotini/identity/middleware_test.py index a0a29db..a18ef1b 100644 --- a/backend/rotini/auth/middleware_test.py +++ b/backend/rotini/identity/middleware_test.py @@ -1,8 +1,8 @@ import pytest import django.http import django.contrib.auth -import auth.middleware -import auth.jwt +import identity.middleware +import identity.jwt AuthUser = django.contrib.auth.get_user_model() @@ -18,7 +18,7 @@ def fixture_jwt_middleware(): def _noop(_: django.http.HttpRequest): return django.http.HttpResponse() - return auth.middleware.JwtMiddleware(_noop) + return identity.middleware.JwtMiddleware(_noop) def test_middleware_does_not_append_user_details_to_request_if_invalid_credentials( @@ -40,7 +40,7 @@ def test_middleware_adds_user_to_request_in_if_valid_token( """If authorization headers are present and contain a valid JWT, sets user on request.""" mock_request = HttpRequestWithUser() test_user = AuthUser.objects.get(username=test_user_credentials["username"]) - token = auth.jwt.generate_token_for_user(test_user.id) + token = identity.jwt.generate_token_for_user(test_user.id) mock_request.COOKIES["jwt"] = token jwt_middleware(mock_request) diff --git a/backend/rotini/identity/urls.py b/backend/rotini/identity/urls.py new file mode 100644 index 0000000..f7d0f03 --- /dev/null +++ b/backend/rotini/identity/urls.py @@ -0,0 +1,11 @@ +import django.urls +import identity.views + +urlpatterns = [ + django.urls.path( + "session/", identity.views.SessionListView.as_view(), name="auth-session-list" + ), + django.urls.path( + "user/", identity.views.UserListView.as_view(), name="auth-user-list" + ), +] diff --git a/backend/rotini/auth/view_test.py b/backend/rotini/identity/view_test.py similarity index 94% rename from backend/rotini/auth/view_test.py rename to backend/rotini/identity/view_test.py index 47e13aa..9006082 100644 --- a/backend/rotini/auth/view_test.py +++ b/backend/rotini/identity/view_test.py @@ -1,4 +1,4 @@ -import auth.jwt +import identity.jwt import pytest @@ -69,6 +69,6 @@ def test_user_login_returns_valid_token_on_success(create_user_request, login_re assert "jwt" in login_response.cookies - decoded_token = auth.jwt.decode_token(login_response.cookies["jwt"].value) + decoded_token = identity.jwt.decode_token(login_response.cookies["jwt"].value) assert decoded_token["user_id"] == create_user_data["id"] diff --git a/backend/rotini/auth/views.py b/backend/rotini/identity/views.py similarity index 96% rename from backend/rotini/auth/views.py rename to backend/rotini/identity/views.py index 25f5688..9d9ac7a 100644 --- a/backend/rotini/auth/views.py +++ b/backend/rotini/identity/views.py @@ -1,11 +1,12 @@ import logging +import uuid import django.http import django.contrib.auth import rest_framework.views import rest_framework.status -import auth.jwt +import identity.jwt AuthUser = django.contrib.auth.get_user_model() @@ -45,7 +46,8 @@ class SessionListView(rest_framework.views.APIView): if user is not None: django.contrib.auth.login(request, user) - token = auth.jwt.generate_token_for_user(user_id=user.id) + token = identity.jwt.generate_token_for_user(user_id=user.id) + response = django.http.HttpResponse(status=201) response.set_cookie( diff --git a/backend/script/start.sh b/backend/script/start.sh index bf251e5..c024c69 100644 --- a/backend/script/start.sh +++ b/backend/script/start.sh @@ -24,4 +24,5 @@ docker run \ --name $APP_CONTAINER_NAME \ --env-file ../backend.env \ --network rotini-local \ + -v ./rotini:/app/rotini \ rotini:dev