setupTOTP method

  1. @override
Future<(String, Uri?)> setupTOTP({
  1. String? appName,
})
override

Setup Time-based One Time Password MFA for the logged in user

returns the secret to be used by a token generator app like Google Authenticate app and the URI for setting up an authenticator app

Implementation

@override
Future<(String, Uri?)> setupTOTP({String? appName}) async {
  try {
    final result = await _amplifyAuth.setUpTotp();
    _logger.fine(
      'Successfully set up TOTP for user: $result',
    );

    if (appName == null) {
      return (result.sharedSecret, null);
    } else {
      return (
        result.sharedSecret,
        result.getSetupUri(
          appName: appName,
          accountName: await getLoggedInUsername(),
        ),
      );
    }
  } on aws_cognito.AuthException catch (e) {
    throw TOTPSetupException(
      message: 'Failed to setup TOTP for user',
      innerException: e,
      innerStackTrace: StackTrace.current,
    );
  }
}