x-amazon-apigateway-authorizer objek - APIGerbang Amazon

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

x-amazon-apigateway-authorizer objek

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

Nama properti Tipe Deskripsi
type string

Jenis otorisasi. Ini adalah properti yang diperlukan.

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

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

authorizerUri string

Uniform Resource Identifier (URI) dari fungsi Lambda authorizer. 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

Kredensi yang diperlukan untuk memanggil otorisasi, jika ada, dalam ARN bentuk peran eksekusi. IAM Misalnya, “arn:aws:iam::account-id:IAM_role".

authorizerPayloadFormatVersion string

Untuk HTTPAPIs, tentukan format data yang dikirimkan API Gateway ke otorisasi Lambda, dan API bagaimana Gateway menafsirkan respons dari Lambda. Untuk mempelajari selengkapnya, lihat Versi format payload.

enableSimpleResponses Boolean

Untuk HTTPAPIs, menentukan apakah request otorisasi mengembalikan nilai Boolean atau kebijakan. IAM Didukung hanya untuk otorisasi dengan authorizerPayloadFormatVersion dari. 2.0 Jika diaktifkan, fungsi Lambda authorizer mengembalikan nilai Boolean. Untuk mempelajari selengkapnya, lihat Respons fungsi Lambda untuk format 2.0.

identitySource string

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

jwtConfiguration Object

Menentukan penerbit dan audiens untuk otorisasi. JWT Untuk mempelajari lebih lanjut, lihat JWTConfigurationdi API Referensi API Gateway Versi 2. Didukung hanya untuk HTTPAPIs.

identityValidationExpression string

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

authorizerResultTtlInSeconds string

Jumlah detik selama hasil otorisasi di-cache.

providerARNs Sebuah array string

Daftar kumpulan pengguna Amazon Cognito ARNs untuk. COGNITO_USER_POOLS

x-amazon-apigateway-authorizer contoh untuk REST APIs

Contoh definisi API keamanan Terbuka berikut menentukan otorisasi Lambda dari jenis “token” dan bernama. 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 API operasi Terbuka berikut menetapkan GET /http untuk menggunakan otorisasi 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 API keamanan Terbuka berikut menentukan otorisasi Lambda dari jenis “permintaan”, dengan parameter header tunggal auth () sebagai sumber identitas. securityDefinitionsItu 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 API keamanan Terbuka berikut menentukan otorisasi Lambda dari jenis “permintaan”, dengan satu header HeaderAuth1 () dan satu QueryString1 parameter string kueri 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 API keamanan Terbuka berikut menentukan otorisasi API Gateway Lambda dari jenis “permintaan”, dengan variabel tahap tunggal 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 API keamanan Terbuka berikut menentukan kumpulan pengguna Amazon Cognito sebagai otorisasi.

"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 API operasi Terbuka berikut menyetel 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" } } }

x-amazon-apigateway-authorizer contoh untuk HTTP APIs

Contoh Open API 3.0 berikut membuat JWT otorisasi untuk HTTP API 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 Open API 3.0 berikut menghasilkan JWT authorizer yang sama dengan contoh sebelumnya. Namun, contoh ini menggunakan API openIdConnectUrl properti Open untuk mendeteksi penerbit secara otomatis. openIdConnectUrlHarus 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 authorizer Lambda untuk file. HTTP API Authorizer contoh ini menggunakan Authorization header sebagai sumber identitasnya. Authorizer menggunakan versi format 2.0 payload, dan mengembalikan nilai Boolean, karena enableSimpleResponses diatur 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 } } }