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

Nens auth client #13

Merged
merged 6 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class APIOverview(views.APIView):

def get(self, request, format=None):
data = {
"api-token": drf_reverse(
"token_obtain_pair", request=request, format=format
),
"userprofile": drf_reverse(
"api:userprofile-list", request=request, format=format
),
Expand Down
25 changes: 18 additions & 7 deletions brostar/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
from datetime import timedelta
from pathlib import Path

FIELD_ENCRYPTION_KEY = os.getenv("FIELD_ENCRYPTION_KEY")
NENS_AUTH_ISSUER = os.getenv("NENS_AUTH_ISSUER")
NENS_AUTH_CLIENT_ID = os.getenv("NENS_AUTH_CLIENT_ID")
NENS_AUTH_CLIENT_SECRET = os.getenv("NENS_AUTH_CLIENT_SECRET")
# Environment variables can get a default value from docker-compose itself *or* from a
# `.env` file, as docker-compose automatically reads that (if the environment variable
# itself is mentioned in the compose file).
Expand All @@ -26,13 +28,18 @@

ALLOWED_HOSTS = []

CSRF_TRUSTED_ORIGINS = [
"http://localhost:4200",
]


# Application definition

INSTALLED_APPS = [
"api.apps.ApiConfig",
"gmn.apps.GmnConfig",
"gmw.apps.GmwConfig",
"nens_auth_client",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand All @@ -43,7 +50,6 @@
"drf_yasg",
"corsheaders",
"django_filters",
"rest_framework_simplejwt",
"encrypted_model_fields",
]

Expand All @@ -58,6 +64,15 @@
"corsheaders.middleware.CorsMiddleware",
]


AUTHENTICATION_BACKENDS = [
"nens_auth_client.backends.RemoteUserBackend",
"nens_auth_client.backends.AcceptNensBackend",
"nens_auth_client.backends.TrustedProviderMigrationBackend",
"django.contrib.auth.backends.ModelBackend",
]


ROOT_URLCONF = "brostar.urls"

TEMPLATES = [
Expand Down Expand Up @@ -161,9 +176,9 @@
"PAGE_SIZE": 1000,
"DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
"DEFAULT_AUTHENTICATION_CLASSES": (
"nens_auth_client.rest_framework.OAuth2TokenAuthentication",
"rest_framework.authentication.BasicAuthentication",
"rest_framework.authentication.SessionAuthentication",
"rest_framework_simplejwt.authentication.JWTAuthentication",
),
}

Expand All @@ -177,7 +192,3 @@
BRO_UITGIFTE_SERVICE_URL = "https://publiek.broservices.nl"
BRONHOUDERSPORTAAL_URL = "https://acc.bronhouderportaal-bro.nl"
# BRONHOUDERSPORTAAL_URL = "https://www.bronhouderportaal-bro.nl"

SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(hours=5),
}
13 changes: 4 additions & 9 deletions brostar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@
from django.urls import include, path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from nens_auth_client.urls import override_admin_auth, override_rest_framework_auth
from rest_framework import permissions
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)

from api import views

schema_view = get_schema_view(
openapi.Info(
Expand All @@ -41,17 +36,17 @@
)

urlpatterns = [
path("auth/", include("nens_auth_client.urls", namespace="auth")),
*override_admin_auth(),
path("admin/", admin.site.urls),
*override_rest_framework_auth(),
path(
"swagger/",
schema_view.with_ui("swagger", cache_timeout=0),
name="schema-swagger-ui",
),
path("redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
path("api/", include(("api.urls", "api"), namespace="api")),
path("api/token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
path("api-auth/logout/", views.LogoutView.as_view(), name="logout"),
]


Expand Down
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
environment:
- DJANGO_SETTINGS_MODULE=brostar.settings
- FIELD_ENCRYPTION_KEY="DUMMY-NEEDS-PROD-SETTING-Xgb1GczqZe909UMNc4=
- NENS_AUTH_ISSUER
- NENS_AUTH_CLIENT_ID
- NENS_AUTH_CLIENT_SECRET
build: .
command: celery -A brostar worker --loglevel=INFO
volumes:
Expand Down Expand Up @@ -48,9 +51,9 @@ services:
- DEBUG
- FIELD_ENCRYPTION_KEY="DUMMY-NEEDS-PROD-SETTING-Xgb1GczqZe909UMNc4=
# - SENTRY_DSN
# - NENS_AUTH_ISSUER
# - NENS_AUTH_CLIENT_ID
# - NENS_AUTH_CLIENT_SECRET
- NENS_AUTH_ISSUER
- NENS_AUTH_CLIENT_ID
- NENS_AUTH_CLIENT_SECRET
depends_on:
- db
- redis
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-e .[test]
--extra-index-url https://packages.lizard.net

# TODO: dependencies
django == 5.0.1
Expand All @@ -17,7 +18,7 @@ xmltodict
python-dotenv
django-encrypted-model-fields
django-filter
djangorestframework-simplejwt
nens-auth-client

# development tools
ruff
Expand Down