I need to do an HTTP call using AJAX with an already authenticated user using Django.
Is there any standard simple way to do this? I've read this other question but uses a different technology.
I'm using HTTP (not HTTPS) and using a third-party app like django-tastypie for this unique "simple" purpose would be overkill, wouldn't it?
To send a GET request with a Bearer Token authorization header using JavaScript/AJAX, you need to make an HTTP GET request and provide your Bearer Token with the Authorization: Bearer {token} HTTP header.
To send and receive data to and from a web server, AJAX uses the following steps: Create an XMLHttpRequest object. Use the XMLHttpRequest object to exchange data asynchronously between the client and the server. Use JavaScript and the DOM to process the data.
Ajax requests are no different from any other kind of request. If the user is already authenticated, then the Ajax request will be authenticated too: the session cookie which identifies the user will be sent along with the Ajax request just as it would be with any other one.
(That linked question is irrelevant because it is talking about authenticating the user within the request, not using an already-authenticated user as you want.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With