AWS API Gateway Method Test: Error Authorization not configured
Asked Answered
O

6

8

I've created a RESTful API on AWS and I'm trying to test the POST method. I give a sample request to the the request body in the api gatemway console's test interface it get this response:

{
  "Error": "Authorization not configured",
  "Reference": "e6b7ec86-97fe-11e7-b480-ebefe7f11420"
}

I originally had this set to a Cognito User Pool with read/write access to a corresponding table, but I got this error message. I tried removing authorization in the method just to test this, but again I received this error.

As far as I can tell, I have authorization set up across the board.

  • IAM role created to add, update, query, and delete, from table (trusted entities: AWS service: lambda) and the AWSLambdaBasicExecutionRole
  • Lambda function using an existing (above) role
  • authorizer created using my User Pool for authorization
  • resource and method (POST) created using cognito user pool authorizer from above

I feel like I must be missing something obvious, but everything seems to be in order as I step through it here. Any help is much appreciated and please let me know if I can provide any additional information.

Order answered 12/9, 2017 at 21:31 Comment(1)
Did you try adding the API Gateway as one of the Lambda function triggers?Alisiaalison
C
20

I found this question linked from the AWS forums The OP there and I both ran into this same problem while going through the Wild Rydes tutorial.

I was able to solve this problem by:

  1. In the API's settings under "Resources", click on the "POST" method, then click on "Method Request".

enter image description here

  1. In the Method Request settings, click the edit icon for "Authorization"

enter image description here

  1. Choose the Cognito pool.

enter image description here

  1. Click the check icon to save the change

enter image description here

Once the change is made, the method request should no longer say None for auth

enter image description here

  1. Redeploy the API.

enter image description here

Correction answered 30/12, 2017 at 21:34 Comment(2)
Nice, I forgot to redeploy the API after changing the Auth property.Tautology
I forgot to click on the confirm button, but now it works! ThanksAllopathy
C
3

If anyone else is having this problem, I simply had to clear my cached data on my browser for it to work.

Cyrenaica answered 8/11, 2019 at 10:23 Comment(0)
O
0

Well, I figured it out after looking through the WildRydes tutorial and Lambda Test. I needed to set the Authorization header to the current user's JWT token. I did this with the following function:

getCurrentAuthToken: function (userPool) {
  return new Promise(function fetchCurrentAuthToken (resolve, reject) 
    let cognitoUser = userPool.getCurrentUser()

    if (cognitoUser) {
      cognitoUser
        .getSession(function sessionCallback (err, session) {
          if (err) {
            reject(err)
          } else if (!session.isValid()) {
            resolve(null)
          } else {
            resolve(session.getIdToken().getJwtToken())
          }
        })
    } else {
      resolve(null)
    }
  })
}

and use the returned value of the promise to set the Authorization header in my request.

Order answered 12/9, 2017 at 22:23 Comment(1)
Where I need to put that function?Kimon
K
0

I have gone through the German version of this tutorial and they translated the value of the token source too, which is wrong at this point.
I just had to change the token source in the API Gateway to the English phrase Authorization and deploy the API again and it worked.

Kirstenkirsteni answered 16/5, 2020 at 9:7 Comment(0)
K
0

I had issues until I set the Auth to none in the OPTIONS Method Request.

Select OPTIONS on the left then click Method Request. Make sure Authorization is set to NONE. Remember to deploy the changes.

Komara answered 12/1, 2021 at 22:12 Comment(0)
S
0

Kindly confirm where we need to put the below code.

getCurrentAuthToken: function (userPool) { return new Promise(function fetchCurrentAuthToken (resolve, reject) let cognitoUser = userPool.getCurrentUser()

if (cognitoUser) {
  cognitoUser
    .getSession(function sessionCallback (err, session) {
      if (err) {
        reject(err)
      } else if (!session.isValid()) {
        resolve(null)
      } else {
        resolve(session.getIdToken().getJwtToken())
      }
    })
} else {
  resolve(null)
}

}) }

Soembawa answered 27/3, 2023 at 2:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.