Get `request.authenticated_userid` in `tween`

Viewed 11

Can I access request.authenticated_userid in a tween? According to https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/router.html authorization appears to happen within the territories where tweens operate.

If I add a tween to my application like:

config.add_tween("jsq.lib.middleware.my_tween.my_tween_factory")

And then I have it like:

def my_tween_factory(handler, registry):
        def my_tween_callback(request):
            print("Auth'd user:", request.authenticated_userid)
            return handler(request)
    return handler

When I do this (and have an authenticated user in session) request.authenticated_userid is None.

0 Answers
Related