add simplejwt to authorization setup #4926
Open
+53
−14
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.
What's this PR do?
Add simplejwt support to the authorization options, adds an additional block to handle bearer tokens
How to test
This PR enables you to get a set of authorization and refresh tokens by authenticating against SEED:
curl -X POST -H 'Content-Type: application/json' -d '{"username":"[email protected]", "password":"password"}' http://localhost/api/token/
That will return a refresh and access token:
{"refresh":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTczNzA2MDk4MSwiaWF0IjoxNzM2OTc0NTgxLCJqdGkiOiIzNmRmZjhmMzYwNTc0NjBhYTk3MTJiNTYzZjgzNjg2MyIsInVzZXJfaWQiOjJ9.PampCBSI2djMnfmx8MZv4oocvEVfd_hrY4k238nX81Q","access":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzM2OTc0ODgxLCJpYXQiOjE3MzY5NzQ1ODEsImp0aSI6ImIwYTdkMjYwODc4MDQ3ZmI4YmQ4NGIwMTJjM2JjZGJlIiwidXNlcl9pZCI6Mn0.3Dq7lQ1KVbEDkUn12Qyt2MhZXDpZmPdbjwyhu77PhmI"}
The access token can then be used as a bearer token for authorization:
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzM2OTcxMjEyLCJpYXQiOjE3MzY5NzA5MTIsImp0aSI6ImI2NWZjZDc5OWJlYTQyOGQ4ZGQzYzI1OWQxMzYxODJjIiwidXNlcl9pZCI6Mn0.q0gVvHpujfTPzB0Nye019AzNdPo6M1RPCK8A3uZfBME" -X POST "http://localhost/api/v3/properties/filter/?cycle=2&ids_only=false&include_related=true&organization_id=1&page=1&per_page=100"
These steps are taken from here: https://django-rest-framework-simplejwt.readthedocs.io/en/stable/getting_started.html