django-shared-session icon indicating copy to clipboard operation
django-shared-session copied to clipboard

Django 2.2 breaks code

Open BarnabasSzabolcs opened this issue 6 years ago • 1 comments

Hi Viktor, great project! Unfortunately there's a breaking change in Django 2.2 that results in:

AttributeError at /
'str' object has no attribute 'decode'

at
return urlsafe_base64_encode(enc_payload).decode('ascii')

In the new version you don't need to decode it anymore, they say on Stackoverflow.

Also this project does not seem to do SSO when I configure it as told in the readme. (Did you leave out a middleware by accident?)

BarnabasSzabolcs avatar Oct 23 '19 15:10 BarnabasSzabolcs

Got same issue. Here's my temporary solution applied to Jinja extension.py

def shared_session(request):
    from shared_session.templatetags.shared_session import LoaderNode

    class ByPass(LoaderNode):
        """
            https://github.com/ViktorStiskala/django-shared-session/issues/11
        """
        def get_message(self,request, domain):
            enc_payload = self.encrypt_payload({
                'key': request.session.session_key,
                'src': request.META['HTTP_HOST'],
                'dst': domain,
                'ts': timezone.now().isoformat()
            })
            return urlsafe_base64_encode(enc_payload)

    return ByPass().render({'request': request})

I copied exactly method except decoding in return

Blucknote avatar Nov 25 '19 09:11 Blucknote