Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
If I don't use request.user in middleware, all apis works well with basic authentication. So I guess, it is not related with basic authentication. On Sun, Dec 1, 2019 at 8:30 AM Wanderley S wrote: > Please send a screenshot with the headers > > Em sáb, 30 de nov de 2019 18:19, Yery cs escreveu:

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Wanderley S
Please send a screenshot with the headers Em sáb, 30 de nov de 2019 18:19, Yery cs escreveu: > I use postman to test api. > Can you tell me how to test api for you? > > > On Sun, Dec 1, 2019 at 5:11 AM Yery cs wrote: > >> Is there any relation with python version? >> >> On Sun, Dec 1, 2019 at 5

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Wanderley S
Postman is good. But seems that you doing it wrong. I believe shouldn't use Basic Auth. You just on headers and set the JWT token. For the token part that depends which token middleware you're using. You should have an endpoint to send a post with the username and password that will return the tok

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
I use postman to test api. Can you tell me how to test api for you? On Sun, Dec 1, 2019 at 5:11 AM Yery cs wrote: > Is there any relation with python version? > > On Sun, Dec 1, 2019 at 5:08 AM Oleg Nykolyn wrote: > >> Last idea - could it possibly be that you set header in a different way ? >

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
Is there any relation with python version? On Sun, Dec 1, 2019 at 5:08 AM Oleg Nykolyn wrote: > Last idea - could it possibly be that you set header in a different way ? > It's quite mysterious that same code work differently, so maybe reason is > in client's request... > I use following command

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Oleg Nykolyn
Last idea - could it possibly be that you set header in a different way ? It's quite mysterious that same code work differently, so maybe reason is in client's request... I use following command(https://httpie.org as http client): ``` http GET 127.0.0.1:8000/api/test/ Authorization:Bearer\ "eyJ0e

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
Yes. I have extracted from project you sent. I have checked two files and all changes can be seen. On Sun, Dec 1, 2019 at 4:57 AM Oleg Nykolyn wrote: > Hi, > > I get following output: > > [30/Nov/2019 20:53:35] *"POST /api/test/ HTTP/1.1" 405 41* > > admin > > None > > *** > > [30/No

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Oleg Nykolyn
Hi, I get following output: [30/Nov/2019 20:53:35] *"POST /api/test/ HTTP/1.1" 405 41* admin None *** [30/Nov/2019 20:54:34] "GET /api/test/ HTTP/1.1" 200 18 Have you extracted code from archive attached to previous message ? It contains changes in middleware.py and settings.py -

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
Hello. thanks for your help. Unfortunately, I still get AnonymousUser. Can you check once more again? On Sun, Dec 1, 2019 at 4:40 AM Oleg Nykolyn wrote: > Hi, > > Here is custom middleware, which works for this case, also > attached project with applied changes - it now show "admin" instead of

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Oleg Nykolyn
Hi, Here is custom middleware, which works for this case, also attached project with applied changes - it now show "admin" instead of AnonymousUser. Reason why DRF doesn't show user in middleware - DRF does not provide it's own middleware for this and sets user only when it processes views. So an

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Wanderley S
Nothing to be sorry about. I'll take a look at your code later, since I'm on mobile now. Can you show me the code where you make the request? You're using curl or some javascript client? Em sáb, 30 de nov de 2019 17:10, Yery cs escreveu: > Hello, thanks for you reply. > Sorry for my poor post

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
This is my prepared project for testing. Of course not main project. You can run on your local. You can migrate and loaddata users.json. password: admin You can test using postman. http://localhost:8000/api/test/ You can see 'AnonymousUser' on your console. I hope it can be fixed. Thank you. On

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
On Sun, Dec 1, 2019 at 4:13 AM Yery cs wrote: > > > On Sun, Dec 1, 2019 at 4:10 AM Wanderley S wrote: > >> Questions: >> 1 - have you created a login view to retrieve the token? >> >> 2- in your request, from client, are you sending the token returned above >> within the header? >> >> The flow i

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
On Sun, Dec 1, 2019 at 4:10 AM Wanderley S wrote: > Questions: > 1 - have you created a login view to retrieve the token? > > 2- in your request, from client, are you sending the token returned above > within the header? > > The flow is: > 1 - authenticate user > 2 - get the token > 3 - send the

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
Hello, thanks for you reply. Sorry for my poor post. I understand concepts of Django authentication. I am using DRF jwt. I have added my custom middleware after Authentication middleware in settings file. And I am printing request.user in console like this `print(request.user)` in my custom middlew

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Wanderley S
Questions: 1 - have you created a login view to retrieve the token? 2- in your request, from client, are you sending the token returned above within the header? The flow is: 1 - authenticate user 2 - get the token 3 - send the token in header for every request Em sáb, 30 de nov de 2019 17:04,

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
> > Hello, Thanks for your reply. > > I have already checked this github comments. I added custom middleware in settings middlewares after Authentication middleware. But I got still Anonymous user. About test, can you explain about force_login? About project status, I am printing logs in console

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Wanderley S
Hi there's no issue there. Let me explain some basics In "pure" Django a cookie called "csrftoken" is the responsible to control authentication and sessions. Hence, for all request Django receives this cookie is sent. When building REST Api's you are not supposed to have any state at server side,

Re: AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Oleg Nykolyn
Hi, Does this happen during real requests or in test-cases ? For real HTTP request custom middleware might be the answer, please check https://github.com/GetBlimp/django-rest-framework-jwt/issues/45 Such middleware should override "request.user" using REST_FRAMEWORK. DEFAULT_AUTHENTICATION_CLASSES

AnonymousUser in DjangoRestFramework Middleware

2019-11-30 Thread Yery cs
Hello, How are you? I am suck with Django Rest framework issue. I am trying to use `request.user` in Django Rest Framework middleware. It returns AnonymousUser and I failed. I have searched and searched but there is no answer. I wonder if this is Django Rest framework issue. Who faced this is

Re: get_serializer_class don't work in GenericViewSet

2019-11-30 Thread Carl Nobile
It seems that you have both the serializer_class member object and the get_serializer_class method set. Remove the serializer_class. On Thursday, November 21, 2019 at 8:21:44 PM UTC-5, Cristian Benavides Jimenez wrote: > > Hi everybody, > > I try use a two serializers in one view inherits

Re: is_authenticated returns false in DRF, true outside DRF

2019-11-30 Thread Carl Nobile
The request.user.is_authenticated() is always true unless the requester is the Annonymous user. Are you sure you logged in and that you are the requester before looking at that value? On Thursday, November 28, 2019 at 8:26:29 AM UTC-5, Eric Gustavsson wrote: > > Hey, > > I've setup mozilla-djan

While running unit tests the wrong parser is being used.

2019-11-30 Thread Carl Nobile
I'm trying to run my unit tests using JSON however I'm getting this error: {'detail': ErrorDetail(string='XML parse error - not well-formed (invalid token): line 1, column 0', code='parse_error')} My settings are: REST_FRAMEWORK = { ... 'DEFAULT_PARSER_CLASSES': ( 'rest_framewo