testAuthorization method
Tests if a specified principal is authorized to perform an IoT action on a specified resource. Use this to test and debug the authorization behavior of devices that connect to the IoT device gateway.
Requires permission to access the TestAuthorization action.
May throw InternalFailureException.
May throw InvalidRequestException.
May throw LimitExceededException.
May throw ResourceNotFoundException.
May throw ServiceUnavailableException.
May throw ThrottlingException.
May throw UnauthorizedException.
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) 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 {
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);
}