View a markdown version of this page

objek x-amazon-apigateway-authorizer - Amazon API Gateway

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

objek x-amazon-apigateway-authorizer

Mendefinisikan otorisasi Lambda, kumpulan pengguna Amazon Cognito, atau otorizer JWT yang akan diterapkan untuk otorisasi pemanggilan metode di API Gateway. Ekstensi ini berlaku untuk definisi keamanan di OpenAPI 2 dan skema keamanan di OpenAPI 3.

Nama properti Tipe Deskripsi
type string

Jenis otorisasi. Ini adalah properti yang diperlukan.

Untuk REST API, tent token ukan otorisasi dengan identitas pemanggil yang disematkan dalam token otorisasi. Tentukan request untuk otorisasi dengan identitas pemanggil yang terkandung dalam parameter permintaan. T cognito_user_pools entukan otorisasi yang menggunakan kumpulan pengguna Amazon Cognito untuk mengontrol akses ke API Anda.

Untuk HTTP API, tentukan request untuk otorizer Lambda dengan identitas pemanggil yang terkandung dalam parameter permintaan. Tentukan jwt untuk otorisasi JWT.

authorizerUri string

Uniform Resource Identifier (URI) dari fungsi Lambda otorizer. Sintaksnya adalah sebagai berikut:

"arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:account-id:function:auth_function_name/invocations"
authorizerCredentials string

KredenSIAL yang diperlukan untuk memanggil otorizer, jika ada, dalam bentuk ARN dari peran eksekusi IAM. Misalnya, “arn:aws:iam:::”. account-id IAM_role

authorizerPayloadFormatVersion string

Untuk API HTTP, tentukan format data yang dikirim API Gateway ke otorizer Lambda, dan bagaimana API Gateway menafsirkan respons dari Lambda. Untuk mempelajari selengkapnya, lihat Versi format muatan.

enableSimpleResponses Boolean

Untuk HTTP API, tentukan apakah request otorizer mengembalikan nilai Boolean atau kebijakan IAM. Didukung hanya untuk otorisasi dengan authorizerPayloadFormatVersion of2.0. Jika diaktifkan, fungsi otorisasi Lambda mengembalikan nilai Boolean. Untuk mempelajari selengkapnya, lihat Respons fungsi Lambda untuk format 2.0.

identitySource string

Daftar ekspresi pemetaan yang dipisahkan koma dari parameter permintaan sebagai sumber identitas. Berlaku untuk otorisasi jwt jenis request dan saja.

jwtConfiguration Object

Menentukan penerbit dan audiens untuk otorisasi JWT. Untuk mempelajari selengkapnya, lihat JWTConfiguration di Referensi API Gateway Versi 2 API. Haya didukung untuk API HTTP.

identityValidationExpression string

Ekspresi reguler untuk memvalidasi token sebagai identitas masuk. Misalnya, “^x- [a-z] +”. Didukung hanya untuk TOKEN otorisasi untuk REST API.

authorizerResultTtlInSeconds string

Jumlah detik selama hasil otorizer di-cache.

providerARNs Sebuah array string

Daftar ARN kumpulan pengguna Amazon Cognito untuk. COGNITO_USER_POOLS

contoh x-amazon-apigateway-authorizer untuk REST API

Contoh definisi keamanan OpenAPI berikut menentukan otorizer Lambda dari tipe “token” dan diberi nama. test-authorizer

"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" : "custom", // 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 } } }

Cuplikan objek operasi OpenAPI berikut menetapkan GET /http untuk menggunakan otorizer Lambda sebelumnya.

"/http" : { "get" : { "responses" : { }, "security" : [ { "test-authorizer" : [ ] } ], "x-amazon-apigateway-integration" : { "type" : "http", "responses" : { "default" : { "statusCode" : "200" } }, "httpMethod" : "GET", "uri" : "http://api.example.com" } } }

Contoh definisi keamanan OpenAPI berikut menentukan otorizer Lambda dari tipe “request”, dengan parameter header tunggal (auth) sebagai sumber identitas. Itu securityDefinitions dinamairequest_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", // Request 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 } } }

Contoh definisi keamanan OpenAPI berikut menentukan otorizer Lambda dari tipe “request”, dengan satu header (HeaderAuth1) dan satu parameter string kueri QueryString1 sebagai sumber identitas.

"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 } } }

Contoh definisi keamanan OpenAPI berikut menentukan otorisasi API Gateway Lambda dari tipe “request”, dengan variabel satu tahap (stage) sebagai sumber identitas.

"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 } } }

Contoh definisi keamanan OpenAPI berikut menentukan kumpulan pengguna Amazon Cognito sebagai otorizer.

"securityDefinitions": { "cognito-pool": { "type": "apiKey", "name": "Authorization", "in": "header", "x-amazon-apigateway-authtype": "cognito_user_pools", "x-amazon-apigateway-authorizer": { "type": "cognito_user_pools", "providerARNs": [ "arn:aws:cognito-idp:us-east-1:123456789012:userpool/us-east-1_ABC123" ] } }

Cuplikan objek operasi OpenAPI berikut menetapkan GET /http untuk menggunakan kumpulan pengguna Amazon Cognito sebelumnya sebagai otorisasi, tanpa cakupan khusus.

"/http" : { "get" : { "responses" : { }, "security" : [ { "cognito-pool" : [ ] } ], "x-amazon-apigateway-integration" : { "type" : "http", "responses" : { "default" : { "statusCode" : "200" } }, "httpMethod" : "GET", "uri" : "http://api.example.com" } } }

contoh x-amazon-apigateway-authorizer untuk HTTP API

Contoh OpenAPI 3.0 berikut membuat otorisasi JWT untuk API HTTP yang menggunakan Amazon Cognito sebagai penyedia identitas, dengan Authorization header sebagai sumber identitas.

"securitySchemes": { "jwt-authorizer-oauth": { "type": "oauth2", "x-amazon-apigateway-authorizer": { "type": "jwt", "jwtConfiguration": { "issuer": "https://cognito-idp.region.amazonaws.com/userPoolId", "audience": [ "audience1", "audience2" ] }, "identitySource": "$request.header.Authorization" } } }

Contoh OpenAPI 3.0 berikut menghasilkan otorizer JWT yang sama seperti contoh sebelumnya. Namun, contoh ini menggunakan openIdConnectUrl properti OpenAPI untuk mendeteksi penerbit secara otomatis. Itu openIdConnectUrl harus sepenuhnya terbentuk.

"securitySchemes": { "jwt-authorizer-autofind": { "type": "openIdConnect", "openIdConnectUrl": "https://cognito-idp.region.amazonaws.com/userPoolId/.well-known/openid-configuration", "x-amazon-apigateway-authorizer": { "type": "jwt", "jwtConfiguration": { "audience": [ "audience1", "audience2" ] }, "identitySource": "$request.header.Authorization" } } }

Contoh berikut membuat otorisasi Lambda untuk API HTTP. Contoh otorizer ini menggunakan Authorization header sebagai sumber identitasnya. Authorizer menggunakan versi format 2.0 payload, dan mengembalikan nilai Boolean, karena enableSimpleResponses disetel ke. true

"securitySchemes" : { "lambda-authorizer" : { "type" : "apiKey", "name" : "Authorization", "in" : "header", "x-amazon-apigateway-authorizer" : { "type" : "request", "identitySource" : "$request.header.Authorization", "authorizerUri" : "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789012:function:function-name/invocations", "authorizerPayloadFormatVersion" : "2.0", "authorizerResultTtlInSeconds" : 300, "enableSimpleResponses" : true } } }