django-ninja-jwt icon indicating copy to clipboard operation
django-ninja-jwt copied to clipboard

The fields required for generating a token.

Open afanzaimoyu opened this issue 1 year ago • 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 avatar Dec 15 '23 16:12 afanzaimoyu

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

eadwinCode avatar Dec 17 '23 16:12 eadwinCode

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 avatar Dec 17 '23 16:12 hardcoded-pro

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

hardcoded-pro avatar Dec 17 '23 16:12 hardcoded-pro

Thanks, I think I'll do it

afanzaimoyu avatar Jan 19 '24 05:01 afanzaimoyu