0

Im usgin Laravel Sanctum auth for my API. When i try to make a call to an endpoint that is handled by 'auth:sanctum' middleware, i cannot put the 'Authorization' header cause if i use it, i get the error "GET http://myapi.host.com/api/user net::ERR_EMPTY_RESPONSE".

I tought that could be my server config but donde this with Postman and it works fine, but it does not in browser.

Does anyone know why this happends?

I'm usgin Angular in an Ionic app This is my API call

const headers = new HttpHeaders({
      Authorization: `Bearer ${await this.apiHelper.getToken()}`
    });

    this.http
      .get(`${this.uri}/api/user`, {
        headers: headers,
      })
      .subscribe(
        (res) => console.log(res),
        (error) => console.log(error)
      );

this is the message i get: "GET http://myapi.host.com/api/user net::ERR_EMPTY_RESPONSE"

if i try a call without 'Authorization' header it works, like this:



    this.http
      .get(`${this.uri}/api/user`)
      .subscribe(
        (res) => console.log(res),
        (error) => console.log(error)
      );

and i get this: "GET http://myapi.host.com/api/user 401 (Unauthorized)" so i cannot authenticate anything

2
  • Is this a cross-domain request, so that CORS restrictions would apply? sjoerdlangkemper.nl/2018/09/12/authorization-header-and-cors Commented Jun 8, 2023 at 7:12
  • yeah, CORS restrictions apply, I have already configured the config/cors.php file on laravel, but do you know how do I respond with a header "Access-Control-Allow-Credentials: true" from the server side? Commented Jun 8, 2023 at 14:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.