Baz
Baz

Reputation: 13135

Call to fetch returning 401

If I run the following:

fetch('http://localhost:8080/root/1487171054127/k_query_bearer_token',{mode: 'no-cors'}).
then(response=>response)

from within my webapp hosted via localhost:11111 I get a 401 error.

However if I open a tab in the same browser and enter http://localhost:8080/root/1487171054127/k_query_bearer_token then I get a 200 response.

What am I doing wrong?

UPDATE

This is working via curl:

curl 'http://localhost:8080/gui/root/1487171054127/k_query_bearer_token' -H 'Cookie: JSESSIONID=CviS9IK8pcsqADdP-m0MRXX_AvUqfzjJPwk1Yytf.ee16d0a01ad5'

So I need to provide a cookie

Upvotes: 2

Views: 3853

Answers (1)

Scymex
Scymex

Reputation: 1074

To automatically send cookies for the current domain, the credentials option must be provided:

fetch('/users', {
  credentials: 'same-origin'
})

Upvotes: 11

Related Questions