2

I have a strange situation. I have a React app which invokes an API Gateway endpoint REST API (GET method). Whenever I run the app (from localhost), I am getting an "unauthorized" (401) error response.

However when I invoke the same API on POSTMAN , I get the correct response with 200 status. And then strangely when I run the app, I am able to get the same correct response with 200 status on the browser also!

I am not able to resolve for the past two weeks, so would appreciate any help on this please. Thanks in advance!

  • Can you check in network tab of browser developer tools and in postman, that both requests are the same? – stirante Dec 02 '19 at 15:16
  • @stirante. Thanks for the quick response! Yes, I checked in both Safari and Chrome dev tools and the request with headers are same with Postman. And the behaviour is consistent also - that is, when I successfully invoke the API in Postman, I get the same correct response in both browsers also! – Vaidya Siva Dec 02 '19 at 15:29
  • Have you seen [this](https://stackoverflow.com/questions/35190615/api-gateway-cors-no-access-control-allow-origin-header)? I'm thinking maybe it has something to do with Access-Control-Allow-Credentials – stirante Dec 02 '19 at 22:25
  • Thanks @stirante. I have tried all that to no avail. I tried invoking the api via cURL before and after invoking in Postman. Same behaviour - before invoking in Postman, cURL also returns 401 unauthorized but after invoking in Postman, works perfectly in cURL. Don't know what action Postman is doing that the credentials work fine for cURL or in the browser. – Vaidya Siva Dec 03 '19 at 06:27
  • Did you ever solved it? Have same issue – helpper Apr 27 '21 at 05:12

1 Answers1

0

Invoking API GW API from localhost will not work - as the localhost is the local machine and not AWS server where the service is active. To invoke a API hosted on AWS one must login using IAM credentials (as you mentioned postman aws signature) or use SDK to access using IAM credentials.

Atlas
  • 61
  • 1
  • 1