I'm trying to implement a custom IAuthorizationPolicy
in Kinto. The documentation points to https://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/authorization.html, which does not make me entirely understand how to add my IAuthorizationPolicy
to the Kinto app.
My solution is to make it into a plugin, and implement the includeme
function like this:
def includeme(config):
custom_authorization_policy = CustomAuthorizationPolicy()
config.set_authorization_policy(custom_authorization_policy)
But later, in IAuthorizationPolicy#permits
, I would like to access the request
that is currently being processed. This is because I want to cache the authentication tokens, and, as I understand it, the cache can be accessed from the request
.
However, the IAuthorizationPolicy#permits
takes the context
parameter, and on it I can't find any request or cache.
The cache, if supported, can be accessed on
config.registry.cache
aswell, so I'm injecting it into my Auth policy: