fix session auth and restrict it only to access_token view
This commit is contained in:
@@ -8,4 +8,5 @@ urlpatterns = [
|
|||||||
path("", include("allauth.urls")),
|
path("", include("allauth.urls")),
|
||||||
path("ssoproviders/", views.GetAddSSOProvider.as_view()),
|
path("ssoproviders/", views.GetAddSSOProvider.as_view()),
|
||||||
path("ssoproviders/<int:pk>/", views.GetUpdateDeleteSSOProvider.as_view()),
|
path("ssoproviders/<int:pk>/", views.GetUpdateDeleteSSOProvider.as_view()),
|
||||||
|
path("ssoproviders/token/", views.GetAccessToken.as_view()),
|
||||||
]
|
]
|
||||||
@@ -7,6 +7,9 @@ from rest_framework.response import Response
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from accounts.permissions import AccountsPerms
|
from accounts.permissions import AccountsPerms
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from rest_framework.authentication import SessionAuthentication
|
||||||
|
from knox.views import LoginView as KnoxLoginView
|
||||||
|
from django.contrib.auth import logout
|
||||||
|
|
||||||
class SocialAppSerializer(ModelSerializer):
|
class SocialAppSerializer(ModelSerializer):
|
||||||
server_url = ReadOnlyField(source="settings.server_url")
|
server_url = ReadOnlyField(source="settings.server_url")
|
||||||
@@ -102,3 +105,16 @@ class GetUpdateDeleteSSOProvider(APIView):
|
|||||||
provider.delete()
|
provider.delete()
|
||||||
return Response("ok")
|
return Response("ok")
|
||||||
|
|
||||||
|
|
||||||
|
class GetAccessToken(KnoxLoginView):
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
authentication_classes = [SessionAuthentication]
|
||||||
|
|
||||||
|
def post(self, request, format=None):
|
||||||
|
response = super().post(request, format=None)
|
||||||
|
response.data["username"] = request.user.username
|
||||||
|
|
||||||
|
#invalid user session since we have an access token now
|
||||||
|
logout(request)
|
||||||
|
return Response(response.data)
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class AuditMiddleware:
|
|||||||
# gather and save debug info
|
# gather and save debug info
|
||||||
debug_info["url"] = request.path
|
debug_info["url"] = request.path
|
||||||
debug_info["method"] = request.method
|
debug_info["method"] = request.method
|
||||||
debug_info["view_class"] = view_func.cls.__name__
|
debug_info["view_class"] = view_func.cls.__name__ if hasattr(view_func, "cls") else None
|
||||||
debug_info["view_func"] = view_Name
|
debug_info["view_func"] = view_Name
|
||||||
debug_info["view_args"] = view_args
|
debug_info["view_args"] = view_args
|
||||||
debug_info["view_kwargs"] = view_kwargs
|
debug_info["view_kwargs"] = view_kwargs
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ REST_FRAMEWORK = {
|
|||||||
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
|
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
|
||||||
"DEFAULT_AUTHENTICATION_CLASSES": (
|
"DEFAULT_AUTHENTICATION_CLASSES": (
|
||||||
"knox.auth.TokenAuthentication",
|
"knox.auth.TokenAuthentication",
|
||||||
"allauth.account.auth_backends.AuthenticationBackend",
|
|
||||||
"tacticalrmm.auth.APIAuthentication",
|
"tacticalrmm.auth.APIAuthentication",
|
||||||
),
|
),
|
||||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||||
@@ -199,9 +198,9 @@ CHANNEL_LAYERS = {
|
|||||||
|
|
||||||
# settings for django all auth
|
# settings for django all auth
|
||||||
HEADLESS_ONLY = True
|
HEADLESS_ONLY = True
|
||||||
|
SOCIALACCOUNT_ONLY = True
|
||||||
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"
|
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"
|
||||||
ACCOUNT_EMAIL_VERIFICATION = 'none'
|
ACCOUNT_EMAIL_VERIFICATION = 'none'
|
||||||
SOCIALACCOUNT_ONLY = True
|
|
||||||
SOCIALACCOUNT_EMAIL_AUTHENTICATION = True
|
SOCIALACCOUNT_EMAIL_AUTHENTICATION = True
|
||||||
SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT = True
|
SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT = True
|
||||||
SOCIALACCOUNT_EMAIL_VERIFICATION = True
|
SOCIALACCOUNT_EMAIL_VERIFICATION = True
|
||||||
@@ -212,6 +211,7 @@ SOCIALACCOUNT_PROVIDERS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AUTHENTICATION_BACKENDS = ("allauth.account.auth_backends.AuthenticationBackend",)
|
||||||
SESSION_COOKIE_SECURE = True
|
SESSION_COOKIE_SECURE = True
|
||||||
|
|
||||||
# silence cache key length warnings
|
# silence cache key length warnings
|
||||||
|
|||||||
Reference in New Issue
Block a user