You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my project, there are several entities that must be able to authorize. How can I write a custom token generation for each entity.
p.s. there was an option to use RefreshToken.for_user but it only uses the user model
The text was updated successfully, but these errors were encountered:
You're definitely on the right track! I highly recommend overriding for_user such that you can decide which model to override. Unfortunately, I think this is a complex case that is out of scope for this library's implementation, but we're happy to guide!
I believe a good solution would be to extend the RefreshToken class' constructor such that it can accept a new value that you determine in the view/serializer. In the view/serializer, you can determine which entity to select, then pass that entity. For example (the below example may be slightly wrong as I answer a ton of issues, but it'll get you on the right track):
classRefreshToken(rest_framework_simplejwt):
def__init__(self, *args, **kwargs):
self.entity_to_use=kwargs.get("entity")
deffor_user(self, *args, **kwargs):
# Override this portion to define your routing# In settings.py"refresh_token_class": "path.to.RefreshToken"
In my project, there are several entities that must be able to authorize. How can I write a custom token generation for each entity.
p.s. there was an option to use RefreshToken.for_user but it only uses the user model
The text was updated successfully, but these errors were encountered: