Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This might be better as a standalone package if it could also be used by the config service or other future services
When enabled this will add a "madoc" dictionary to each request object. If a JWT is present it will be parsed (NOT validated)
and the data extracted.
The resulting object will be something like this:
There are a few classes that wrap the above structure.
You can use either
request.madoc.site.urn
orrequest.madoc.site.id
if you want to apply apre-applied filter on a site. Note, this will not be usable if
request.madoc.gateway
isTrue
.Additionally a recreation of a Madoc internal function that is used for requiring a JWT + scope has been added.
In a view, you can pass in a request object and a list of required scopes.
To enable, you need to install the middleware in
settings.py
MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", + "madoc.middleware.MadocMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", ]
You can use
user_with_scope()
if you don't have the middleware installed and it will skip over it. Thatmay be useful for development or when search is used without JWTs.
Next steps for the library may be to generalise the shape of the above parsed token that could be used
outside of a Madoc context. Also it may be useful to have search specific scopes. (e.g.
search.read
,search.admin
) andmake the "admin" context configurable (If you have
site.admin
scope, then you have any others).Fixes #6
Original Typescript implementations