-
Notifications
You must be signed in to change notification settings - Fork 673
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
Serializer responsability #24
Comments
Maybe it does. Although the single responsibility principle is more of a guideline than a rule. In practice, it's not possible to rigorously adhere to that principle. In my experience, form and serializer classes usually end up doing more than just serialization tasks and form stuff and it's awkward to avoid that. You're welcome to try and figure out a (hopefully) simple modification to the library that will enable you to do what you need and submit it as a PR. |
Okay, I will make a propose. Thanks for you attention! 😄 |
#27 I try to make the minimum changes but I add some test to this new "feature" |
I'll try and find some time in the next few days to look over this. Mostly looks good at a glance. |
Yeep, it's all okay? @davesque |
I think it may be possible to use the http://www.django-rest-framework.org/api-guide/serializers/#including-extra-context That article talks about including "extra" context. However, I'm pretty sure that a fair amount of information is included in this context attribute by default. Of course, I think you'll still have to create and use a custom serializer. |
I am having issues with 'django axes' due to it requiring the request to authenticate. @davesque looking through the code is there any reason why the authentication cannot be moved to the JWTAuthentication class? This seems to be standard with the examples in restframework and I would have thought make things cleaner. |
@davesque I think that using
|
Honestly, this just seems too specific to your particular use case. I suggest you just use this pattern in your project and that we keep it separate from the main fork of simple jwt for now. |
As per a discussion in another issue, I'm starting to see more how the way our serializers work is kind of problematic. I'll have to revisit this at a later time because it seems like a bit of work. Ideally, if we were to change this, I think it would involve moving all token logic outside of serializers and into views. I think I had made the serializers work the way they do because I saw them as performing the task of validating data provided in the request and also producing the object that will be serialized in the response. This sometimes might involve accessing contextual information such as the request object. I think the DRF author Tom Christie also shares this view since he made that kind of information available through the Anyway, we'll have to take another look at this. |
Good! I will try to find some time this week to think about it... |
one way this could be solved is by removing the authentication from the serializer and let users configure what authentication backend they want to use to sign in. adapt the views accordingly and initialize the serializer with the user object instead. |
We currently do something with But I agree with @loicgasser . I don't think we need to stick with how DRF does the validation; it's more like how this package can evolve to be a little more flexible for developers. |
I can see that serializers in this library are authenticating users. Does this break the Single Responsability Principle? In my project I want to pass the request object to the authentication method but as it is coupled with serialization I can not do it without rewriting the entire
TokenObtainSerializer
.The text was updated successfully, but these errors were encountered: