From ef9d88db73c52e06ed4757d025adfb145411fad5 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 19 Jan 2022 13:17:55 +0100 Subject: [PATCH] #75 Propagate users * extends KonovaSSOClient for providing support of propagated user data from sso-server. For longterm, we hope to have this feature directly on django-simple-sso. Further details can be found here: https://github.com/divio/django-simple-sso/issues/67 --- konova/sso/sso.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/konova/sso/sso.py b/konova/sso/sso.py index f33376fc..f3038428 100644 --- a/konova/sso/sso.py +++ b/konova/sso/sso.py @@ -5,17 +5,51 @@ Contact: michel.peltriaux@sgdnord.rlp.de Created on: 17.08.21 """ +from django.http import HttpResponse +from django.urls import re_path +from django.views import View +from django.views.decorators.csrf import csrf_exempt +from itsdangerous import TimedSerializer from simple_sso.sso_client.client import Client from user.models import User +class PropagateView(View): + """ View used to receive propagated sso-server user data + + """ + client = None + signer = None + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.signer = TimedSerializer(self.client.private_key) + + @csrf_exempt + def dispatch(self, request, *args, **kwargs): + return super().dispatch(request, *args, **kwargs) + + def post(self, request): + user_data = request.body + user_data = self.signer.loads(user_data) + self.client.build_user(user_data) + return HttpResponse(status=200) + + class KonovaSSOClient(Client): - """ Konova specialized derivate of general sso.Client. + """ Konova specialized derivative of general sso.Client. Adds some custom behaviour for konova usage. """ + propagate_view = PropagateView + + def get_urls(self): + urls = super().get_urls() + urls += re_path(r'^propagate/$', self.propagate_view.as_view(client=self), name='simple-sso-propagate'), + return urls + def build_user(self, user_data): """ Creates a user or updates user data