[英]Access AWS API Gateway from Axios
I am attempting to access AWS API Gateway-hosted services from Axios. 我正在尝试从Axios访问AWS API Gateway托管的服务。 Using AWS Amplify, I obtain a token using Auth.currentSession() which delivers a CognitoIdToken .
使用AWS Amplify,我使用Auth.currentSession()获取令牌,该令牌提供CognitoIdToken 。 Embedded within that object is a jwtToken.
嵌入在该对象中的是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.
我试图使用HTTP标头中的jwtToken调用我的受保护服务(授权器设置为AWS_IAM),同时尝试授权和x-api-key密钥,两者都没有任何乐趣。 Given a CognitoIdToken/jwtToken, how do you call an AWS API Gateway service with an authorizer of AWS_IAM?
给定CognitoIdToken / jwtToken,您如何使用AWS_IAM的授权者调用AWS API网关服务?
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. 如果您正在使用AWS_IAM身份验证,则需要将AWS SigV4与您的cognito用户获取的访问密钥,密钥和会话密钥一起使用,作为其授权的一部分。
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. 如果您想使用cognito JWT作为身份验证机制,则需要更改代码以在API网关级别使用身份验证身份验证。
I have been using API gateways along with Cognito for authorization for my Vuejs app. 我一直在使用API网关和Cognito来授权我的Vuejs应用程序。 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 您可以点击此链接以获取有关AWS中模板的更多详细信息, 请访问https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.