x-amazon-apigateway-authorizer オブジェクト
API Gateway でのメソッド呼び出しの許可に適用される Lambda オーソライザー (以前のカスタムオーソライザー) を定義します。このオブジェクトは、OpenAPI Security Definitions オブジェクトの拡張プロパティです。
プロパティ
プロパティ名 | タイプ | 説明 |
---|---|---|
type |
string |
認証のタイプ。これは必須のプロパティです。認証トークンに組み込まれた発信者 ID を持つオーソライザーの場合は、 |
authorizerUri |
string |
オーソライザー Lambda 関数の Uniform Resource Identifier (URI)。構文は次のとおりです。
|
authorizerCredentials |
string |
IAM 実行ロールの ARN 形式でオーソライザーを呼び出すのに必要な認証情報 (ある場合)。たとえば、"arn:aws:iam:: |
identitySource |
string |
ID ソースとして、リクエストパラメータの式をマッピングするカンマ区切りのリスト。タイプが「request」のみのオーソライザーにのみ適用できます。 |
identityValidationExpression |
string |
入力のアイデンティティとしてトークンを検証するための正規表現。たとえば、"^x-[a-z]+" などです。 |
authorizerResultTtlInSeconds |
string |
作成される IAM ポリシーがキャッシュされる秒数。 |
x-amazon-apigateway-authorizer の例
次の OpenAPI セキュリティ定義の例では、test-authorizer
という「token」タイプの Lambda オーソライザーを指定します。
"securityDefinitions" : { "test-authorizer" : { "type" : "apiKey", // Required and the value must be "apiKey" for an API Gateway API. "name" : "Authorization", // The name of the header containing the authorization token. "in" : "header", // Required and the value must be "header" for an API Gateway API. "x-amazon-apigateway-authtype" : "oauth2", // Specifies the authorization mechanism for the client. "x-amazon-apigateway-authorizer" : { // An API Gateway Lambda authorizer definition "type" : "token", // Required property and the value must "token" "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", "authorizerCredentials" : "arn:aws:iam::account-id
:role", "identityValidationExpression" : "^x-[a-z]+", "authorizerResultTtlInSeconds" : 60 } } }
次の OpenAPI オペレーションオブジェクトのスニペットでは、上記で指定した Lambda オーソライザーを使用するよう GET /http
を設定します。
"/http" : { "get" : { "responses" : { }, "security" : [ { "test-authorizer" : [ ] } ], "x-amazon-apigateway-integration" : { "type" : "http", "responses" : { "default" : { "statusCode" : "200" } }, "httpMethod" : "GET", "uri" : "http://api.example.com" } } }
次の OpenAPI セキュリティ定義の例では、単一のヘッダーパラメータ (auth
) を ID ソースとして使用して、「request」タイプの Lambda オーソライザーを指定します。securityDefinitions
の名前は request_authorizer_single_header
です。
"securityDefinitions": { "request_authorizer_single_header" : { "type" : "apiKey", "name" : "auth", // The name of a single header or query parameter as the identity source. "in" : "header", // The location of the single identity source request parameter. The valid value is "header" or "query" "x-amazon-apigateway-authtype" : "custom", "x-amazon-apigateway-authorizer" : { "type" : "request", "identitySource" : "method.request.header.auth", // Reqeust parameter mapping expression of the identity source. In this example, it is the 'auth' header. "authorizerCredentials" : "arn:aws:iam::123456789012:role/AWSepIntegTest-CS-LambdaRole", "authorizerUri" : "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:APIGateway-Request-Authorizer:vtwo/invocations", "authorizerResultTtlInSeconds" : 300 } } }
次の OpenAPI セキュリティ定義の例では、1 つのヘッダー (HeaderAuth1
) とクエリ文字列パラメータ (QueryString1
) を ID ソースとして使用して、「request」タイプの Lambda オーソライザーを指定します。
"securityDefinitions": { "request_authorizer_header_query" : { "type" : "apiKey", "name" : "Unused", // Must be "Unused" for multiple identity sources or non header or query type of request parameters. "in" : "header", // Must be "header" for multiple identity sources or non header or query type of request parameters. "x-amazon-apigateway-authtype" : "custom", "x-amazon-apigateway-authorizer" : { "type" : "request", "identitySource" : "method.request.header.HeaderAuth1, method.request.querystring.QueryString1", // Request parameter mapping expressions of the identity sources. "authorizerCredentials" : "arn:aws:iam::123456789012:role/AWSepIntegTest-CS-LambdaRole", "authorizerUri" : "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:APIGateway-Request-Authorizer:vtwo/invocations", "authorizerResultTtlInSeconds" : 300 } } }
次の OpenAPI セキュリティ定義の例では、単一のステージ変数 (stage
) を ID ソースとして使用して、「request」タイプの API Gateway Lambda オーソライザーを指定します。
"securityDefinitions": { "request_authorizer_single_stagevar" : { "type" : "apiKey", "name" : "Unused", // Must be "Unused", for multiple identity sources or non header or query type of request parameters. "in" : "header", // Must be "header", for multiple identity sources or non header or query type of request parameters. "x-amazon-apigateway-authtype" : "custom", "x-amazon-apigateway-authorizer" : { "type" : "request", "identitySource" : "stageVariables.stage", // Request parameter mapping expression of the identity source. In this example, it is the
stage
variable. "authorizerCredentials" : "arn:aws:iam::123456789012:role/AWSepIntegTest-CS-LambdaRole", "authorizerUri" : "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:APIGateway-Request-Authorizer:vtwo/invocations", "authorizerResultTtlInSeconds" : 300 } } }