我应该将什么用作 Cognito 的 UserContextData => EncodedData?

What should I use as Cognito's UserContextData => EncodedData?

在大多数函数的所有 AWS Cognito SDK 中,您可以传递一个 UserContextData 参数来提供 Cognito 的高级安全功能:

$result = $client->forgotPassword([
  'AnalyticsMetadata' => [
    'AnalyticsEndpointId' => '<string>',
  ],
  'ClientId' => '<string>', // REQUIRED
  'SecretHash' => '<string>',
  'UserContextData' => [  // <=================== THIS
    'EncodedData' => '<string>',
  ],
  'Username' => '<string>', // REQUIRED
]);  

该字段需要一些 EncodedData

我应该在 UserContextData 中输入什么以及如何 "encode" 它?

当使用像AdminInitiateAuth这样的Admin*函数时,我可以通过ContextData发送未编码的指纹数据:

$result = $client->adminInitiateAuth([
    [...]
    'ContextData' => [
        'EncodedData' => '<string>',
        'HttpHeaders' => [ // REQUIRED
            [
                'headerName' => '<string>',
                'headerValue' => '<string>',
            ],
            // ...
        ],
        'IpAddress' => '<string>', // REQUIRED
        'ServerName' => '<string>', // REQUIRED
        'ServerPath' => '<string>', // REQUIRED
    ],
    [...]
]);

documentation没有帮助:

AWS 为用户上下文数据提供 opaque implementation

encodedData 将在设备而非服务器上收集。

Cognito Javascript client SDK exposes a method to achieve this. It is provided for in the Amplify Android SDK

您可以获得从客户端到服务器的传输 encodedData,然后在您的请求中将其转发给 Cognito。