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

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

x-amazon-apigateway-authorizer oggetto

Definisce un autorizzatore Lambda, un pool di utenti Amazon Cognito o un JWT autorizzatore da applicare per l'autorizzazione delle chiamate ai metodi in Gateway. API Questa estensione si applica alla definizione di sicurezza in Open 2 e Open 3. API API

Nome proprietà Tipo Descrizione
type string

Il tipo di autorizzazione. Questa proprietà è obbligatoria.

Per RESTAPIs, specificare token un autorizzatore con l'identità del chiamante incorporata in un token di autorizzazione. Specificare request per un'autorizzazione con l'identità dell'intermediario contenuta nei parametri della richiesta. Specificare cognito_user_pools un autorizzatore che utilizzi un pool di utenti Amazon Cognito per controllare l'accesso al tuo. API

Per HTTPAPIs, specificare request un autorizzatore Lambda con l'identità del chiamante contenuta nei parametri della richiesta. Specificare un jwt autorizzatore. JWT

authorizerUri string

L'Uniform Resource Identifier (URI) della funzione Lambda dell'autorizzatore. La sintassi è esposta di seguito:

"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

Le credenziali richieste per richiamare l'autorizzatore, se del caso, sotto forma di ruolo di esecuzione. ARN IAM Ad esempio, «arn:aws:iam::account-id:IAM_role".

authorizerPayloadFormatVersion string

For HTTPAPIs, specifica il formato dei dati che API Gateway invia a un sistema di autorizzazione Lambda e il API modo in cui Gateway interpreta la risposta di Lambda. Per ulteriori informazioni, consulta Tipo di formato payload.

enableSimpleResponses Boolean

Per HTTPAPIs, specifica se un request autorizzatore restituisce un valore booleano o una politica. IAM Supportato solo per le autorizzazioni con un authorizerPayloadFormatVersion 2.0. Se abilitata, la funzione del provider di autorizzazioni Lambda restituisce un valore booleano. Per ulteriori informazioni, consulta Risposta della funzione Lambda per il formato 2.0.

identitySource string

Un elenco separato da virgole di espressioni di mappatura dei parametri di richiesta come origine di identità. Applicabile solo per l'autorizzazione del tipo request e jwt.

jwtConfiguration Object

Speciifica l'emittente e i destinatari di un autorizzatore. JWT Per ulteriori informazioni, consulta il riferimento alla versione 2 JWTConfigurationdi API Gateway. API Supportato solo per HTTPAPIs.

identityValidationExpression string

Espressione regolare per la convalida del token come identità in ingresso. Ad esempio, "^x-[a-z]+". Supportato solo per gli TOKEN autorizzatori di RESTAPIs.

authorizerResultTtlInSeconds string

Numero di secondi durante i quali il risultato dell'autorizzazione viene memorizzato nella cache.

providerARNs Una matrice di string

Un elenco del pool di utenti di Amazon Cognito ARNs per. COGNITO_USER_POOLS

x-amazon-apigateway-authorizer esempi per REST APIs

Il seguente esempio API di definizioni di sicurezza Open specifica un autorizzatore Lambda del tipo «token» e denominato. 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 } } }

Il seguente frammento di oggetto Open API operation imposta l'utilizzo dell'GET /httpautorizzatore Lambda precedente.

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

Il seguente esempio API di definizioni di sicurezza Open specifica un autorizzatore Lambda del tipo «request», con un singolo parametro di intestazione auth () come origine dell'identità. Il nome di 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", // 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 } } }

Il seguente esempio API di definizioni di sicurezza Open specifica un autorizzatore Lambda del tipo «request», con un parametro header HeaderAuth1 () e un QueryString1 parametro di stringa di query come fonti di identità.

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

Il seguente esempio API di definizioni di sicurezza Open specifica un autorizzatore API Gateway Lambda del tipo «request», con una variabile a fase singola stage () come origine dell'identità.

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

Il seguente esempio API di definizione di sicurezza Open specifica un pool di utenti Amazon Cognito come autorizzatore.

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

Il seguente frammento di oggetto Open API operation imposta l'utilizzo del GET /http precedente pool di utenti di Amazon Cognito come autorizzatore, senza ambiti personalizzati.

"/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 esempi per HTTP APIs

Il seguente esempio di Open API 3.0 crea un JWT autorizzatore per un utente HTTP API che utilizza Amazon Cognito come provider di identità, con Authorization l'intestazione come fonte di identità.

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

Il seguente esempio Open API 3.0 produce lo stesso JWT autorizzatore dell'esempio precedente. Tuttavia, questo esempio utilizza la API openIdConnectUrl proprietà Open per rilevare automaticamente l'emittente. Il openIdConnectUrl deve essere completamente formato.

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

L'esempio seguente crea un autorizzatore Lambda per un. HTTP API In questo esempio l'autorizzazione utilizza l'intestazione Authorization come origine di identità. L'autorizzazione utilizza il tipo di formato payload 2.0 e restituisce il valore booleano, poiché enableSimpleResponses è impostato su 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 } } }