VenomBerry
VenomBerry

Reputation: 301

Authorization header not working Angular 5

I am consuming an JWT based API. I am passing the Authorization header correctly (I mean in the code), using headers.set('Authorization', 'token') and i am using the correct method which is GET.

When i serve the application (using ionic 3), i have the error 405 (Method Not Allowed), but the same request works when i use POSTMAN or i paste the code snippet (generated from POSTMAN) into the console.

Here's two captures of the working request (using code snippet from POSTMAN into the console) and the not working request (from the ionic app).

By the way, there is something weird about the authorization, i highlighted it in red.

Not working request

Working request

Upvotes: 1

Views: 4539

Answers (2)

Ehasanul Hoque
Ehasanul Hoque

Reputation: 650

If it is not a cors issue, you could try according to following code

const httpOptions = {
        headers: new HttpHeaders()
          .set('Authorization',  'Bearer ' +this.auth_token)
      }


    return this.http.get('http://xxxxxx00x:8080/api/clients',httpOptions);

Upvotes: 1

sylwester
sylwester

Reputation: 16498

On the top screen you have got request method OPTIONS not GET and response from the server is 405 Method not allowed not 401 Unauthorized or 403 Forbidden. So the problem is not authorization but request method. Looks like CORS issue.

Upvotes: 0

Related Questions