getId method

Future<GetIdResponse> getId({
  1. required String identityPoolId,
  2. String? accountId,
  3. Map<String, String>? logins,
})

Generates (or retrieves) a Cognito ID. Supplying multiple logins will create an implicit linked account.

This is a public API. You do not need any credentials to call this API.

May throw InvalidParameterException. May throw ResourceNotFoundException. May throw NotAuthorizedException. May throw ResourceConflictException. May throw TooManyRequestsException. May throw InternalErrorException. May throw LimitExceededException. May throw ExternalServiceException.

Parameter identityPoolId : An identity pool ID in the format REGION:GUID.

Parameter accountId : A standard AWS account ID (9+ digits).

Parameter logins : A set of optional name-value pairs that map provider names to provider tokens. The available provider names for Logins are as follows:

  • Facebook: graph.facebook.com
  • Amazon Cognito user pool: cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>, for example, cognito-idp.us-east-1.amazonaws.com/us-east-1_123456789.
  • Google: accounts.google.com
  • Amazon: www.amazon.com
  • Twitter: api.twitter.com
  • Digits: www.digits.com

Implementation

Future<GetIdResponse> getId({
  required String identityPoolId,
  String? accountId,
  Map<String, String>? logins,
}) async {
  ArgumentError.checkNotNull(identityPoolId, 'identityPoolId');
  _s.validateStringLength(
    'identityPoolId',
    identityPoolId,
    1,
    55,
    isRequired: true,
  );
  _s.validateStringLength(
    'accountId',
    accountId,
    1,
    15,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityService.GetId'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    signed: false,
    // TODO queryParams
    headers: headers,
    payload: {
      'IdentityPoolId': identityPoolId,
      if (accountId != null) 'AccountId': accountId,
      if (logins != null) 'Logins': logins,
    },
  );

  return GetIdResponse.fromJson(jsonResponse.body);
}