Reputation: 2763
I am attempting to access AWS API Gateway-hosted services from Axios. Using AWS Amplify, I obtain a token using Auth.currentSession() which delivers a CognitoIdToken. Embedded within that object is a jwtToken. I have attempting to call my protected services (authorizer is set to AWS_IAM) using that jwtToken in the HTTP header, trying both the Authorization and x-api-key key, both with no joy. Given a CognitoIdToken/jwtToken, how do you call an AWS API Gateway service with an authorizer of AWS_IAM?
Upvotes: 2
Views: 4236
Reputation: 658
I have been using API gateways along with Cognito for authorization for my Vuejs app. You can use following steps to get it configured easily.
#set($inputRoot = $input.path('$')) { "cognitoUsername": "$context.authorizer.claims.email" }
You can follow this link to get more details about template in AWS https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
Hope this helps.
Upvotes: 0
Reputation: 1780
If you're using AWS_IAM authentication then you need to use AWS SigV4 with your access key, secret key, and session key that your cognito user gets as part of their authorization.
If you want to use the cognito JWT as your auth mechanism, you need to change your code to use cognito authentication at the API Gateway level.
Upvotes: 1