Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NextAuth to frontend #912

Merged
merged 31 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3023063
Add dependencies
AndyRae Sep 20, 2024
f6e4e66
Update dependencies
AndyRae Sep 20, 2024
29f123c
Add authn app
AndyRae Sep 20, 2024
aeb25c3
Implement authn app in config
AndyRae Sep 20, 2024
2b660fb
Add nextauth
AndyRae Sep 20, 2024
4259cbb
Add env variable for csrf
AndyRae Sep 20, 2024
4cdeb41
Move request to nextauth
AndyRae Sep 20, 2024
1ed1d19
add login
AndyRae Sep 24, 2024
5aab778
Merge branch 'master' into feat/870/next-auth
AndyRae Sep 25, 2024
3dee6b2
Add usermnu
AndyRae Sep 27, 2024
190d0ca
Start of sidebar changes
AndyRae Oct 2, 2024
ef9c410
Merge branch 'master' into feat/870/next-auth
AndyRae Oct 2, 2024
db5f17b
Merge branch 'master' into feat/870/next-auth
AndyRae Nov 1, 2024
90d23a9
Add avatar
AndyRae Nov 3, 2024
4426e0d
Fix type
AndyRae Nov 3, 2024
4b85cea
Add username in menu
AndyRae Nov 3, 2024
4fc1ebf
Remove change password
AndyRae Nov 3, 2024
a2aedd3
Remove test view
AndyRae Nov 3, 2024
b604be6
Clean up urls
AndyRae Nov 3, 2024
baa0075
Remove `django-rev-proxy` dependency
AndyRae Nov 3, 2024
5098c71
Add simple login
AndyRae Nov 3, 2024
51d30ce
Remove comment
AndyRae Nov 3, 2024
b300167
Remove revproxy
AndyRae Nov 3, 2024
1ff4343
Fix dark mode titles
AndyRae Nov 3, 2024
fc6e4d0
Simplify middleware
AndyRae Nov 3, 2024
9a13042
Fix datapartners url
AndyRae Nov 3, 2024
ce1d22c
Replace get current user with session
AndyRae Nov 3, 2024
3ccac9a
Merge branch 'master' into feat/870/next-auth
AndyRae Nov 19, 2024
6e67f3f
Merge branch 'master' into feat/870/next-auth
AndyRae Dec 19, 2024
96ad9c2
Update app/next-client-app/components/core/UserMenu.tsx
AndyRae Dec 19, 2024
fc71c8c
Add api slashes
AndyRae Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/api/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@
name="scan-report-values",
),
path(r"user/me/", views.UserDetailView.as_view(), name="currentuser"),
path(r"v2/users", views.UserViewSet.as_view(), name="users-list"),
path(r"v2/usersfilter", views.UserFilterViewSet.as_view(), name="usersfilter"),
path(r"v2/datapartners", views.DataPartnerViewSet.as_view(), name="datapartners"),
path(r"v2/users/", views.UserViewSet.as_view(), name="users-list"),
path(r"v2/usersfilter/", views.UserFilterViewSet.as_view(), name="usersfilter"),
path(r"v2/datapartners/", views.DataPartnerViewSet.as_view(), name="datapartners"),
path(
r"v2/omop/conceptsfilter",
views.ConceptFilterViewSetV2.as_view(),
Expand Down
Empty file added app/api/authn/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions app/api/authn/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AuthnConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "authn"
16 changes: 16 additions & 0 deletions app/api/authn/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from dj_rest_auth.jwt_auth import get_refresh_view
from dj_rest_auth.registration.views import RegisterView
from dj_rest_auth.views import LoginView, LogoutView, UserDetailsView
from django.urls import path
from django.views.decorators.csrf import get_token
from rest_framework_simplejwt.views import TokenVerifyView

urlpatterns = [
path("register/", RegisterView.as_view(), name="rest_register"),
path("login/", LoginView.as_view(), name="rest_login"),
path("logout/", LogoutView.as_view(), name="rest_logout"),
path("user/", UserDetailsView.as_view(), name="rest_user_details"),
path("token/verify/", TokenVerifyView.as_view(), name="token_verify"),
path("token/refresh/", get_refresh_view().as_view(), name="token_refresh"),
path("csrf-token/", get_token, name="api-csrf-token"),
]
35 changes: 34 additions & 1 deletion app/api/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import os
from datetime import timedelta

from dotenv import load_dotenv

Expand Down Expand Up @@ -50,6 +51,7 @@
# Application definition

INSTALLED_APPS = [
"django.contrib.sites",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand All @@ -68,7 +70,12 @@
"rest_framework.authtoken",
"corsheaders",
"test",
"revproxy",
"authn.apps.AuthnConfig",
"rest_framework_simplejwt",
"allauth",
"allauth.account",
"dj_rest_auth",
"dj_rest_auth.registration",
"shared",
"shared.files",
"shared.jobs",
Expand All @@ -81,11 +88,15 @@
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"allauth.account.middleware.AccountMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
]

CSRF_TRUSTED_ORIGINS = [os.environ.get("NEXTJS_URL", "http://localhost:3000")]
SITE_ID = 1

STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

ROOT_URLCONF = "config.urls"
Expand Down Expand Up @@ -178,6 +189,7 @@
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.TokenAuthentication",
"rest_framework.authentication.SessionAuthentication",
"rest_framework_simplejwt.authentication.JWTAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
}
Expand All @@ -202,3 +214,24 @@
AZ_RULES_NAME = os.environ.get("AZ_RULES_NAME", "RulesOrchestrator")
AZ_RULES_KEY = os.environ.get("AZ_RULES_KEY", "")
AZ_RULES_EXPORT_QUEUE = os.environ.get("AZ_RULES_EXPORT_QUEUE", "rules-exports-local")

# Auth

ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = "none"

SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=60),
"REFRESH_TOKEN_LIFETIME": timedelta(days=7),
"ROTATE_REFRESH_TOKENS": False,
"BLACKLIST_AFTER_ROTATION": False,
"UPDATE_LAST_LOGIN": True,
"SIGNING_KEY": os.getenv("SIGNING_KEY"),
"ALGORITHM": "HS512",
"AUTH_HEADER_TYPES": ("JWT",),
}

REST_AUTH = {
"USE_JWT": True,
"JWT_AUTH_HTTPONLY": False,
}
17 changes: 2 additions & 15 deletions app/api/config/urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
import os

from config import settings
from django.contrib import admin
from django.urls import include, path, re_path
from revproxy.views import ProxyView # type: ignore
from django.urls import include, path

urlpatterns = [
path("api/", include("api.urls")),
path("api_auth/", include("rest_framework.urls", namespace="rest_framework")),
path("api/auth/", include("authn.urls")),
path("admin/", admin.site.urls),
path("accounts/", include("django.contrib.auth.urls")),
(
re_path(r"(?P<path>.*)", ProxyView.as_view(upstream=f"{settings.NEXTJS_URL}/"))
if os.environ.get("ENABLE_PROXY", "False").lower() == "true"
else None
),
path("", include("shared.mapping.urls")),
]

urlpatterns = [url for url in urlpatterns if url is not None]
132 changes: 113 additions & 19 deletions app/api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion app/api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ graphviz = "^0.20.3"
drf-dynamic-fields = "^0.4.0"
django-cors-headers = "^4.4.0"
python-dotenv = "^1.0.1"
django-revproxy = "^0.12.0"
shared = {path = "../shared", develop = true}
azure-monitor-opentelemetry = "^1.6.0"
djangorestframework-simplejwt = "^5.3.1"
django-allauth = "0.61.1"
dj-rest-auth = {extras = ["with-social"], version = "^6.0.0"}

[tool.poetry.group.test.dependencies]
pytest-django = "^4.8.0"
Expand Down
6 changes: 4 additions & 2 deletions app/next-client-app/app/(protected)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import "react-tooltip/dist/react-tooltip.css";
import React from "react";
import { getCurrentUser } from "@/api/users";
import { getServerSession } from "next-auth";
import { options } from "@/auth/options";
import { MenuBar } from "@/components/core/menubar";

export default async function ProtectedLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const user = await getCurrentUser();
const session = await getServerSession(options);
const user = session?.token?.user;

return (
<>
Expand Down
Loading
Loading