aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

Authorizer policy object losing attributes after parse

Open d1sco opened this issue 8 years ago • 1 comments

AWS expects the output of a policy object to look like this


{
  "principalId": "user",
  "policyDocument": {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Action": "execute-api:Invoke",
        "Effect": "Deny",
        "Resource": "arn:aws:execute-api:us-west-2:123456789012:ymy8tbxw7b/*/GET/"
      }
    ]
  }
}

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html

instead my policy object is returned like this

{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Action": "execute-api:Invoke",
        "Effect": "Deny",
        "Resource": "arn:aws:execute-api:us-west-2:123456789012:ymy8tbxw7b/*/GET/"
      }
    ]
  }

my generatePolicy return is formatted exactly like the desired object, when I test my custom authorizer over API Gateway -> Authorizers -> test , i even get the correct policy object BEFORE body parse, after body parse is when i lose my outer object with PrincipalId and PolicyDocument attributes

My Authorizers generatePolicy function

const generatePolicy = (principalId, effect, resource) => {
  return {
    principalId: principalId,
    policyDocument: {
      Version: '2012-10-17',
      Statement: [
        {
          Action: 'execute-api:Invoke',
          Effect: effect,
          Resource: resource
        }
      ]
    },
//optional context
    Context: {
      stringKey: "value",
      numberKey: "1",
      booleanKey: "true"
    }
  }

In my protected endpoint the authroizer object never comes through with proxy under event.contextRequest.authorizer and in mapping template its not anywhere under context/request :/

Edit: sorry im a super dummy and posted this under java sdk , feel free to remove/close i will post under js

d1sco avatar Aug 13 '18 19:08 d1sco

https://github.com/aws/aws-sdk-js/issues/2195

spfink avatar Aug 13 '18 19:08 spfink