associateSoftwareToken method

Future<AssociateSoftwareTokenResponse> associateSoftwareToken({
  1. String? accessToken,
  2. String? session,
})

Begins setup of time-based one-time password (TOTP) multi-factor authentication (MFA) for a user, with a unique private key that Amazon Cognito generates and returns in the API response. You can authorize an AssociateSoftwareToken request with either the user's access token, or a session string from a challenge response that you received from Amazon Cognito. Authorize this action with a signed-in user's access token. It must include the scope aws.cognito.signin.user.admin.

May throw ConcurrentModificationException. May throw ForbiddenException. May throw InternalErrorException. May throw InvalidParameterException. May throw NotAuthorizedException. May throw OperationNotEnabledException. May throw ResourceNotFoundException. May throw SoftwareTokenMFANotFoundException.

Parameter accessToken : A valid access token that Amazon Cognito issued to the currently signed-in user. Must include a scope claim for aws.cognito.signin.user.admin.

You can provide either an access token or a session ID in the request.

Parameter session : The session identifier that maintains the state of authentication requests and challenge responses. In AssociateSoftwareToken, this is the session ID from a successful sign-in. You can provide either an access token or a session ID in the request.

Implementation

Future<AssociateSoftwareTokenResponse> associateSoftwareToken({
  String? accessToken,
  String? session,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityProviderService.AssociateSoftwareToken'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    signed: false,
    // TODO queryParams
    headers: headers,
    payload: {
      if (accessToken != null) 'AccessToken': accessToken,
      if (session != null) 'Session': session,
    },
  );

  return AssociateSoftwareTokenResponse.fromJson(jsonResponse.body);
}