eadwinCode / django-ninja-jwt

A JSON Web Token authentication plugin for the Django REST Framework.
https://eadwincode.github.io/django-ninja-jwt/
MIT License
143 stars 21 forks source link

The fields required for generating a token. #54

Open afanzaimoyu opened 10 months ago

afanzaimoyu commented 10 months ago

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]
eadwinCode commented 10 months ago

@afanzaimoyu You can create your own token generation as shown here

hardcoded-pro commented 10 months ago

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.

hardcoded-pro commented 10 months ago

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).

afanzaimoyu commented 9 months ago

Thanks, I think I'll do it