

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

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

配置授权以控制对您的亚马逊 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>

以下示例为 API 配置了 Lambda 授权方。 WebSocket 

```
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
```