The fields required for generating a token.
afanzaimoyu opened this issue · 4 comments
Hello, when calling the "http://localhost:8000/api/token/pair" endpoint, I need to provide username and password. However, my User model does not have the password field. How can I modify this without changing the source code?
I only know how to make modifications here, but I prefer not to modify the source code:
class TokenObtainInputSchemaBase(ModelSchema, TokenInputSchemaMixin):
class Config:
# extra = "allow"
model = get_user_model()
model_fields = ["password", user_name_field]
@afanzaimoyu You can create your own token generation as shown here
Have the same problem. The problem is in ModelSchema
, because it have metaclass that check django model fields on python module ninja_jwt.schema
load. So if any code use at least one class from ninja_jwt.schema
then ninja.ModelSchema
will validate fields from ninja_jwt.TokenObtainInputSchemaBase.Config.model_fields
and raise error if password field not defined for user model.
So it will be cool to take ninja_jwt.TokenObtainInputSchemaBase.Config.model_fields
from api_settings
. Because variant with own token generation as shown here will not work (use import from ninja_jwt.schema
).
Thanks, I think I'll do it