Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In all AWS Cognito SDKs in most functions you can pass an UserContextData parameter to feed Cognito's Advanced Security feature:

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

This field expects some EncodedData.

What should I put in UserContextData and how do I "encode" it?

When using an Admin* function like AdminInitiateAuth I can send unencoded fingerprinting data through ContextData:

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

The documentation does not help:
enter image description here

like image 826
Quentin Hayot Avatar asked Oct 01 '19 14:10

Quentin Hayot


People also ask

How do I verify my email with Cognito?

Amazon Cognito can automatically verify email addresses or phone numbers. To do this verification, Amazon Cognito sends a verification code or a verification link. For email addresses, Amazon Cognito can send a code or a link in an email message. For phone numbers, Amazon Cognito sends a code in an SMS text message.

What is Srp_a?

SRP_A is basically a large integer generated client side. For example in Java you can do: a = new BigInteger(EPHEMERAL_KEY_LENGTH, SECURE_RANDOM).mod(N); A = g.modPow(a, N); github.com/aws/aws-sdk-android/blob/master/… Where N is a big prime.

What is ClientMetadata?

ClientMetadata. A map of custom key-value pairs that you can provide as input for certain custom workflows that this action triggers. You create custom workflows by assigning AWS Lambda functions to user pool triggers.


1 Answers

AWS provides an opaque implementation for user context data.

encodedData is to be collected on device and not the server.

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

You can get transfer encodedData from client to server, then forward that in your request to Cognito.

like image 148
Oluwafemi Sule Avatar answered Nov 14 '22 23:11

Oluwafemi Sule