Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The fields required for generating a token. #54

Open
afanzaimoyu opened this issue Dec 15, 2023 · 4 comments
Open

The fields required for generating a token. #54

afanzaimoyu opened this issue Dec 15, 2023 · 4 comments

Comments

@afanzaimoyu
Copy link

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
Copy link
Owner

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

@hardcoded-pro
Copy link

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
Copy link

hardcoded-pro commented Dec 17, 2023

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
Copy link
Author

Thanks, I think I'll do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants