AWS API Gateway提供了多种认证方式的支持,可以在同一个端点上同时使用多种认证方式。以下是实现此功能的代码示例。
代码示例:
{
"swagger": "2.0",
"info": {
"title": "My API Gateway",
"version": "1.0"
},
"schemes": [
"https"
],
"securityDefinitions": {
"cognito": {
"name": "Authorization",
"type": "apiKey",
"in": "header",
"x-amazon-apigateway-authtype": "awsSigv4",
"x-amazon-apigateway-authorizer": {
"type": "cognito_user_pools",
"providerARNs": [
"arn:aws:cognito-idp:${region}:${accountId}:userpool/${userPoolId}"
],
"authorizerResultTtlInSeconds": 300
}
},
"iam": {
"name": "Authorization",
"type": "apiKey",
"in": "header",
"x-amazon-apigateway-authtype": "awsSigv4",
"x-amazon-apigateway-authorizer": {
"type": "aws_iam",
"authorizerUri": "arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${authorizerFuncArn}/invocations"
}
}
},
"security": [
{
"cognito": [],
"iam": []
}
],
"paths": {
"/users": {
"get": {
"security": [
{
"cognito": [],
"iam": []
}
],
"responses": {
"200": {
"description": "Successful response"
}
}
},
"post": {
"security": [
{
"cognito": [],
"