I build a Django site wheres requires all users to be authenticated using the standard authentication of Django. In some of the pages django will be doing Request to a third party site which also require authentication.
This third party site is not a django site and only has one user, this means that all django users will be sharing that 1 user to retrieve the information.
The authentication to this third party site, is with a JWT Flow. We first retrieve an auth token and then we send this token to the desire end point adding the Django user ID, to retrieve that user ID information.
I want to avoid all users in django doing multiple request to get the same auth token as this should be the same for all of them.
Is there a way in Django to storage this auth Token safely? and perhaps if a user fail due to expiry token, django retrieves a new one and keep it safely store for all users to use?
In the code which needs access to this 3rd party site token do something like:
remote_token = cache.get_or_set('remote-token', get_remote_token)
get_or_set can take a callable (function) which will be executed only if the cache is not populated yet.
More info here