Hi Carl,

Turns out I was missing
'rest_framework.authentication.SessionAuthentication' from the
DEFAULT_AUTHENTICATION_CLASSES.
After adding that it worked within DRF without issues. Such a simple mistake

Thanks for the help nonetheless :)

Eric Gustavsson, RHCSA

He/Him/His

Software Engineer

Red Hat <https://www.redhat.com>

IM: Telegram: @SpyTec

E1FE 044A E0DE 127D CBCA E7C7 BD1B 8DF2 C5A1 5384
<https://www.redhat.com>


On Sat, 30 Nov 2019 at 19:33, Carl Nobile <carl.nob...@gmail.com> wrote:

> 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-django-oidc, but I'm struggling to get
>> `request.user.is_authenticated` to be true within DRF. I added a router
>> endpoint to the browseable API:
>> return Response({"authenticated": request.user.is_authenticated()})
>>
>> As well as a response outside DRF:
>> return HttpResponse(request.user.is_authenticated())
>>
>> After authentication. DRF returns false, outside DRF returns true.
>> mozilla-django-oidc even has a class extending DRF BasicAuthentication
>>
>> https://github.com/mozilla/mozilla-django-oidc/blob/master/mozilla_django_oidc/contrib/drf.py
>>
>> Which I added to the DRF settings:
>> REST_FRAMEWORK = {
>>     # ...
>>     'DEFAULT_AUTHENTICATION_CLASSES': [
>>         'mozilla_django_oidc.contrib.drf.OIDCAuthentication',
>>     ]
>> }
>>
>> This is all using
>> Django 1.11.15, but I've tested with 2.2 as well.
>> djangorestframework==3.10.3
>>
>> What am I missing to get a user seen as authenticated within DRF?
>>
>> Thanks,
>> Eric
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django REST framework" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-rest-framework/C1ajFUVZG84/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> django-rest-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/f49aa3b1-f9b8-4a04-bf45-9657944dca74%40googlegroups.com
> <https://groups.google.com/d/msgid/django-rest-framework/f49aa3b1-f9b8-4a04-bf45-9657944dca74%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAGoXw-h%3DiYtaqgOQRBKFOyZKspEw9bshGJQZqEtAk5kn80Q7hA%40mail.gmail.com.

Reply via email to