0
votes

I've been constantly getting the "missing authentication token" error when I click the AWS API gateway POST method url through the browser. I set "AUTH" as none and it's working totally fine through Postman but not with the browser. The problem is that I'm using swift to trigger the method and it doesn't seem to be reaching the gateway at all (no log on CloudWatch) and I don't think my code is wrong (or maybe it is). If someone could point out what my mistake is or a solution to this problem I'd appreciate it so much.

P.S. My lambda function is working totally fine and I typed in the right URL (one in the code is just for example)

Here's my code:

func postNonceToServer(paymentMethodNonce: String) {

    let paymentURL = URL(string: "https://example-url.us-east-1.amazonaws.com/prod/create-transaction")!
    var request = URLRequest(url: paymentURL)
    request.httpBody = "\(paymentMethodNonce)".data(using: String.Encoding.utf8)
    request.httpMethod = "POST"
}
3
Do not post pictures of code. Please edit your question by copying and pasting your relevant code into your question as properly formatted text. Pictures are hard to read, can't be searched, and can't be referenced in answers.rmaddy
@rmaddy thanks for the feedback, I updated the code!David Kim
Are you sure you have method and resource for this query in api gateway? Just check it.Dmitry Grinko
@DmitryGrinko yes I have both the method and the resource set up. Even testing works, but it's just the browser that doesn't give me what I wantDavid Kim
Do you remember about re-deploy API? Just check it.Dmitry Grinko

3 Answers

1
votes

In my opinion, this should be a problem in the URL itself. I can think of:

1- Please make sure that the URL is parsed correctly by printing it to the console and pasting it into the browser URL bar. (I have no idea about swift)

2- Make sure that "execute-api" is included in your "example-url", i.e., before the region.

3- Make sure that OPTIONS method has AUTH as none.

Good luck!

0
votes

This mostly would be because of CORS issue.

Please enable CORS in you API gateway like below. After enabling CORS please redeploy the API

If you don't have OPTIONS added, please follow below steps (If OPTIONS already there just add CORS),

  • Create a new OPTIONS method under the /services resource
  • Create and populate the Access-Control-Allow-Origin/Method/Headers in the OPTIONS method.

Enable CORS like below after creating OPTIONS

enter image description here

0
votes

After enabling CORS on my endpoints I was receiving the same error message:

{"message":"Missing Authentication Token"}

Everything checked out, but I consistently received that error. To fix my issue I had to deploy the API. To do that, do the following:

  1. Go to "Amazon API Gateway" console
  2. Click on the API Gateway in question
  3. Click "Resources" and select the root resource, e.g., "/"
  4. Click "Actions" and then "Deploy API"
  5. Select the stage you want to deploy to
  6. Click "Deploy"

Long story short, redeploy the API after you've enabled CORS.