0

Can't get past Django Rest Framework Token Authorization because I can't set withCredentials=true using OkHttp RequestBuilder. (I'm referring to this https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials)

In javascript using axios.post this works fine. I'm having trouble converting this post request to android using OkHttp request builder.

Request builder only seems to give setter methods for Header and Body of post Request?

Tried reading through OkHttp documentation and I've also tried to send withCredentials=True as a header

Django Rest Framework backend not recognizing the token and not resolving the bearer token to a user.

If no class authenticates, request.user will be set to an instance > of django.contrib.auth.models.AnonymousUser, and request.auth > will be set to None.

omgirok
  • 178
  • 2
  • 11

1 Answers1

0

I'm going to assume here that withCredentials is a query parameter. Appending ?withCredentials=true. to the end of the URL will probably get things going for you.

An example in full might look like https://www.example.com?withCredentials=true.

With multiple parameters, it may look like https://www.example.com?withCredentials=true&otherParam=Stuff.

Matt Malec
  • 16
  • 1
  • 3
  • Hey Matt, withCredentials is the XHR property that signifies the usage of a CSRF token/cookie https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials. It is also my understanding that it is NOT recommended to use querystring params in a POST request -- it should be for GET requests only. – omgirok Jul 26 '19 at 16:20
  • My mistake. I'm not too familiar with XHR. – Matt Malec Sep 14 '19 at 04:33