From f00f36fba3cf1b66284862d699e2104958e591f9 Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Sat, 8 Jan 2022 13:15:24 +0530 Subject: [PATCH] keycloak init --- .gitignore | 1 + requirements.txt | 12 ++++++++++++ website/website/settings.py | 10 +++++++++- website/website/urls.py | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0bcdbc3..9c19884 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ venv/ .vscode/ __pycache__/ db.sqlite3 +.env \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 17fac3d..f079ea8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,19 @@ asgiref==3.4.1 +certifi==2021.10.8 +charset-normalizer==2.0.10 Django==4.0 +django-keycloak==0.1.2.dev0 djangorestframework==3.13.1 +ecdsa==0.17.0 +idna==3.3 psycopg2==2.9.2 +pyasn1==0.4.8 Pygments==2.11.2 +python-jose==3.3.0 +python-keycloak-client==0.2.3 pytz==2021.3 +requests==2.27.1 +rsa==4.8 +six==1.16.0 sqlparse==0.4.2 +urllib3==1.26.8 diff --git a/website/website/settings.py b/website/website/settings.py index cf7ad8b..6193d35 100644 --- a/website/website/settings.py +++ b/website/website/settings.py @@ -41,6 +41,7 @@ INSTALLED_APPS = [ 'snippets.apps.SnippetsConfig', 'blog.apps.BlogConfig', 'api.apps.ApiConfig', + 'django_keycloak.apps.KeycloakAppConfig', ] MIDDLEWARE = [ @@ -51,6 +52,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django_keycloak.middleware.BaseKeycloakMiddleware', ] ROOT_URLCONF = 'website.urls' @@ -133,4 +135,10 @@ REST_FRAMEWORK = { 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', ] -} \ No newline at end of file +} + +AUTHENTICATION_BACKENDS = [ + 'django_keycloak.auth.backends.KeycloakAuthorizationCodeBackend', +] + +LOGIN_URL = 'keycloak_login' \ No newline at end of file diff --git a/website/website/urls.py b/website/website/urls.py index 74b2a77..0d3abef 100644 --- a/website/website/urls.py +++ b/website/website/urls.py @@ -13,6 +13,7 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django import urls from django.contrib import admin from django.urls import path, include @@ -23,4 +24,5 @@ urlpatterns = [ urlpatterns += [ path('api-auth/', include('rest_framework.urls')), + path(r'^keycloak/', include('django_keycloak.urls')), ]