x-amazon-apigateway-authtype 财产 - Amazon API Gateway

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

x-amazon-apigateway-authtype 财产

对于 REST API,此扩展可用于定义 Lambda 授权方的自定义类型。在这种情况下,该值为自由格式。例如,一个 API 可能有多个使用不同内部方案的 Lambda 授权方。您可以使用此扩展来标识 Lambda 授权方的内部方案。

更常见的是,在 HTTP API 和 REST API 中,它还可以用作在共享同一安全方案的多个操作中定义 IAM 授权的方法。在这种情况下,术语 awsSigv4 是保留术语,以及前缀为 aws 的任何术语。

此扩展适用于 OpenAPI 2OpenAPI 3 中的 apiKey 类型安全方案。

x-amazon-apigateway-authtype 示例

以下 OpenAPI 3 示例定义了 REST API 或 HTTP API 中的多个资源的 IAM 授权:

{ "openapi" : "3.0.1", "info" : { "title" : "openapi3", "version" : "1.0" }, "paths" : { "/operation1" : { "get" : { "responses" : { "default" : { "description" : "Default response" } }, "security" : [ { "sigv4Reference" : [ ] } ] } }, "/operation2" : { "get" : { "responses" : { "default" : { "description" : "Default response" } }, "security" : [ { "sigv4Reference" : [ ] } ] } } }, "components" : { "securitySchemes" : { "sigv4Reference" : { "type" : "apiKey", "name" : "Authorization", "in" : "header", "x-amazon-apigateway-authtype": "awsSigv4" } } } }

以下 OpenAPI 3 示例使用 REST API 的自定义方案定义了 Lambda 授权方:

{ "openapi" : "3.0.1", "info" : { "title" : "openapi3 for REST API", "version" : "1.0" }, "paths" : { "/protected-by-lambda-authorizer" : { "get" : { "responses" : { "200" : { "description" : "Default response" } }, "security" : [ { "myAuthorizer" : [ ] } ] } } }, "components" : { "securitySchemes" : { "myAuthorizer" : { "type" : "apiKey", "name" : "Authorization", "in" : "header", "x-amazon-apigateway-authorizer" : { "identitySource" : "method.request.header.Authorization", "authorizerUri" : "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:account-id:function:function-name/invocations", "authorizerResultTtlInSeconds" : 300, "type" : "request", "enableSimpleResponses" : false }, "x-amazon-apigateway-authtype": "Custom scheme with corporate claims" } } }, "x-amazon-apigateway-importexport-version" : "1.0" }

另请参阅

authorizer.authType