

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# HttpApiAuth
<a name="sam-property-httpapi-httpapiauth"></a>

設定授權以控制對 Amazon API Gateway HTTP API 的存取。

如需設定 HTTP APIs 存取權的詳細資訊，請參閱[《 API Gateway 開發人員指南》中的在 API Gateway 中控制和管理 HTTP API 的存取權](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-access-control.html)。 **

## 語法
<a name="sam-property-httpapi-httpapiauth-syntax"></a>

若要在 AWS Serverless Application Model (AWS SAM) 範本中宣告此實體，請使用下列語法。

### YAML
<a name="sam-property-httpapi-httpapiauth-syntax.yaml"></a>

```
  [Authorizers](#sam-httpapi-httpapiauth-authorizers): {{OAuth2Authorizer | LambdaAuthorizer}}
  [DefaultAuthorizer](#sam-httpapi-httpapiauth-defaultauthorizer): {{String}}
  [EnableIamAuthorizer](#sam-httpapi-httpapiauth-enableiamauthorizer): {{Boolean}}
```

## Properties
<a name="sam-property-httpapi-httpapiauth-properties"></a>

 `Authorizers`   <a name="sam-httpapi-httpapiauth-authorizers"></a>
用於控制 API Gateway API 存取的授權方。  
*類型*：[OAuth2Authorizer](sam-property-httpapi-oauth2authorizer.md) \| [LambdaAuthorizer](sam-property-httpapi-lambdaauthorizer.md)  
*必要*：否  
*預設*：無  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。  
*其他備註*：將授權方 AWS SAM 新增至 OpenAPI 定義。

 `DefaultAuthorizer`   <a name="sam-httpapi-httpapiauth-defaultauthorizer"></a>
指定用於授權 API Gateway API 呼叫的預設授權方。如果 `EnableIamAuthorizer` 設定為 ，您可以將 指定`AWS_IAM`為預設授權方`true`。否則，請指定您在 中定義的授權方`Authorizers`。  
*類型：*字串  
*必要*：否  
*預設*：無  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `EnableIamAuthorizer`   <a name="sam-httpapi-httpapiauth-enableiamauthorizer"></a>
指定是否使用 API 路由的 IAM 授權。  
*類型*：布林值  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

## 範例
<a name="sam-property-httpapi-httpapiauth--examples"></a>

### OAuth 2.0 授權方
<a name="sam-property-httpapi-httpapiauth--examples--oauth-2.0-authorizer"></a>

OAuth 2.0 授權方範例

#### YAML
<a name="sam-property-httpapi-httpapiauth--examples--oauth-2.0-authorizer--yaml"></a>

```
Auth:
  Authorizers:
    OAuth2Authorizer:
      AuthorizationScopes:
        - scope1
        - scope2
      JwtConfiguration:
        issuer: "https://www.example.com/v1/connect/oauth2"
        audience:
          - MyApi
      IdentitySource: "$request.querystring.param"
  DefaultAuthorizer: OAuth2Authorizer
```

### IAM 授權方
<a name="sam-property-httpapi-httpapiauth--examples--iam-authorizer"></a>

IAM 授權方範例

#### YAML
<a name="sam-property-httpapi-httpapiauth--examples--iam-authorizer--yaml"></a>

```
Auth:
  EnableIamAuthorizer: true
  DefaultAuthorizer: AWS_IAM
```