

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

# 对您的请求进行身份验证
<a name="tracking-identity-pool"></a>

创建跟踪器资源并准备好开始根据地理围栏评估设备位置后，请选择如何对请求进行身份验证：
+ 要探索访问这些服务的方式，请参阅[使用 Amazon Location Service 进行身份验证](access.md)。
+ 如果您想通过未经身份验证的请求发布设备位置，则可能需要使用 Amazon Cognito。

  **示例**：

  以下示例显示了使用 Amazon Cognito 身份池进行授权、使用 [AWS JavaScript SDK v3](https://aws.amazon.com/sdk-for-javascript/) 和 Amazon Location [Web](how-to-auth-helper.md#loc-sdk-auth-web)。

  ```
  import { LocationClient, BatchUpdateDevicePositionCommand } from "@aws-sdk/client-location";
  import { withIdentityPoolId } from "@aws/amazon-location-utilities-auth-helper";
  
  // Unauthenticated identity pool you created
  const identityPoolId = "us-east-1:1234abcd-5678-9012-abcd-sample-id";
  
  // Create an authentication helper instance using credentials from Cognito
  const authHelper = await withIdentityPoolId(identityPoolId);
  
  const client = new LocationClient({
    region: "us-east-1", // The region containing both the identity pool and tracker resource
    ...authHelper.getLocationClientConfig(), // Provides configuration required to make requests to Amazon Location
  });
  
  const input = {
    TrackerName: "ExampleTracker",
    Updates: [
      {
        DeviceId: "ExampleDevice-1",
        Position: [-123.4567, 45.6789],
        SampleTime: new Date("2020-10-02T19:09:07.327Z"),
      },
      {
        DeviceId: "ExampleDevice-2",
        Position: [-123.123, 45.123],
        SampleTime: new Date("2020-10-02T19:10:32Z"),
      },
    ],
  };
  
  const command = new BatchUpdateDevicePositionCommand(input);
  
  // Send device position updates
  const response = await client.send(command);
  ```