getCredentialsForIdentity method

Future<GetCredentialsForIdentityResponse> getCredentialsForIdentity({
  1. required String identityId,
  2. String? customRoleArn,
  3. Map<String, String>? logins,
})

Returns credentials for the provided identity ID. Any provided logins will be validated against supported login providers. If the token is for cognito-identity.amazonaws.com, it will be passed through to AWS Security Token Service with the appropriate role for the token.

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 InvalidIdentityPoolConfigurationException. May throw InternalErrorException. May throw ExternalServiceException.

Parameter identityId : A unique identifier in the format REGION:GUID.

Parameter customRoleArn : The Amazon Resource Name (ARN) of the role to be assumed when multiple roles were received in the token from the identity provider. For example, a SAML-based identity provider. This parameter is optional for identity providers that do not support role customization.

Parameter logins : A set of optional name-value pairs that map provider names to provider tokens. The name-value pair will follow the syntax "provider_name": "provider_user_identifier".

Logins should not be specified when trying to get credentials for an unauthenticated identity.

The Logins parameter is required when using identities associated with external identity providers such as FaceBook. For examples of Logins maps, see the code examples in the External Identity Providers section of the Amazon Cognito Developer Guide.

Implementation

Future<GetCredentialsForIdentityResponse> getCredentialsForIdentity({
  required String identityId,
  String? customRoleArn,
  Map<String, String>? logins,
}) async {
  ArgumentError.checkNotNull(identityId, 'identityId');
  _s.validateStringLength(
    'identityId',
    identityId,
    1,
    55,
    isRequired: true,
  );
  _s.validateStringLength(
    'customRoleArn',
    customRoleArn,
    20,
    2048,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    signed: false,
    // TODO queryParams
    headers: headers,
    payload: {
      'IdentityId': identityId,
      if (customRoleArn != null) 'CustomRoleArn': customRoleArn,
      if (logins != null) 'Logins': logins,
    },
  );

  return GetCredentialsForIdentityResponse.fromJson(jsonResponse.body);
}