

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

# WebSocketApiAuth
<a name="sam-property-websocketapi-websocketapiauth"></a>

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

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

## 語法
<a name="sam-property-websocketapi-websocketapiauth-syntax"></a>

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

### YAML
<a name="sam-property-websocketapi-websocketapiauth-syntax.yaml"></a>

```
[AuthArn](#sam-websocketapiauth-autharn): {{String}}
[AuthType](#sam-websocketapiauth-authtype): {{String}}
[IdentitySource](#sam-websocketapiauth-identitysource): {{List}}
[InvokeRole](#sam-websocketapiauth-invokerole): {{String}}
[Name](#sam-websocketapiauth-name): {{String}}
```

## Properties
<a name="sam-property-websocketapi-websocketapiauth-properties"></a>

 `AuthArn`   <a name="sam-websocketapiauth-autharn"></a>
用於授權的 Lambda 函數 ARN。當 `AuthType`為 時為必要`CUSTOM`。  
*類型：*字串  
*必要*：有條件  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `AuthType`   <a name="sam-websocketapiauth-authtype"></a>
授權的類型。有效值為 `NONE`、`AWS_IAM` 或 `CUSTOM`。  
+ `NONE` - 無授權
+ `AWS_IAM` - IAM 授權
+ `CUSTOM` - Lambda 授權方
*類型：*字串  
*必要*：是  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `IdentitySource`   <a name="sam-websocketapiauth-identitysource"></a>
請求授權的身分來源。例如 `route.request.header.Authorization`。  
*類型：*清單  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::ApiGatewayV2::Authorizer` 資源的 `[IdentitySource](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-identitysource)` 屬性。

 `InvokeRole`   <a name="sam-websocketapiauth-invokerole"></a>
API Gateway 在叫用授權方函數時擔任的 IAM 角色 ARN。如果未指定， AWS SAM 會自動建立資源型許可，允許 API Gateway 叫用授權方函數。  
*類型：*字串  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::ApiGatewayV2::Authorizer` 資源的 `[AuthorizerCredentialsArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-authorizercredentialsarn)` 屬性。

 `Name`   <a name="sam-websocketapiauth-name"></a>
授權方的名稱。  
*類型：*字串  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::ApiGatewayV2::Authorizer` 資源的 `[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-name)` 屬性。

## 範例
<a name="sam-property-websocketapi-websocketapiauth-examples"></a>

### Lambda 授權方
<a name="sam-property-websocketapi-websocketapiauth-examples-lambda"></a>

下列範例會設定 WebSocket API 的 Lambda 授權方。

```
Auth:
  AuthType: CUSTOM
  AuthArn: !GetAtt AuthorizerFunction.Arn
  IdentitySource:
    - route.request.header.Authorization
```

### IAM 授權
<a name="sam-property-websocketapi-websocketapiauth-examples-iam"></a>

下列範例會設定 WebSocket API 的 IAM 授權。

```
Auth:
  AuthType: AWS_IAM
```