testAuthorization method

Future<TestAuthorizationResponse> testAuthorization({
  1. required List<AuthInfo> authInfos,
  2. String? clientId,
  3. String? cognitoIdentityPoolId,
  4. List<String>? policyNamesToAdd,
  5. List<String>? policyNamesToSkip,
  6. String? principal,
})

Tests if a specified principal is authorized to perform an AWS IoT action on a specified resource. Use this to test and debug the authorization behavior of devices that connect to the AWS IoT device gateway.

May throw ResourceNotFoundException. May throw InvalidRequestException. May throw ThrottlingException. May throw UnauthorizedException. May throw ServiceUnavailableException. May throw InternalFailureException. May throw LimitExceededException.

Parameter authInfos : A list of authorization info objects. Simulating authorization will create a response for each authInfo object in the list.

Parameter clientId : The MQTT client ID.

Parameter cognitoIdentityPoolId : The Cognito identity pool ID.

Parameter policyNamesToAdd : When testing custom authorization, the policies specified here are treated as if they are attached to the principal being authorized.

Parameter policyNamesToSkip : When testing custom authorization, the policies specified here are treated as if they are not attached to the principal being authorized.

Parameter principal : The principal. Valid principals are CertificateArn (arn:aws:iot:region:accountId:cert/certificateId), thingGroupArn (arn:aws:iot:region:accountId:thinggroup/groupName) and CognitoId (region:id).

Implementation

Future<TestAuthorizationResponse> testAuthorization({
  required List<AuthInfo> authInfos,
  String? clientId,
  String? cognitoIdentityPoolId,
  List<String>? policyNamesToAdd,
  List<String>? policyNamesToSkip,
  String? principal,
}) async {
  ArgumentError.checkNotNull(authInfos, 'authInfos');
  final $query = <String, List<String>>{
    if (clientId != null) 'clientId': [clientId],
  };
  final $payload = <String, dynamic>{
    'authInfos': authInfos,
    if (cognitoIdentityPoolId != null)
      'cognitoIdentityPoolId': cognitoIdentityPoolId,
    if (policyNamesToAdd != null) 'policyNamesToAdd': policyNamesToAdd,
    if (policyNamesToSkip != null) 'policyNamesToSkip': policyNamesToSkip,
    if (principal != null) 'principal': principal,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/test-authorization',
    queryParams: $query,
    exceptionFnMap: _exceptionFns,
  );
  return TestAuthorizationResponse.fromJson(response);
}