private async Task LoadSharedKeyAndQrCodeUrlAsync(ApplicationUser user, User2faSetupResponseDto dto)
        {
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            dto.SharedKey        = FormatKey(unformattedKey);
            dto.AuthenticatorUrl = GenerateQrCodeUri(user.Email, unformattedKey);
        }
        public async Task <IActionResult> Get2Details()
        {
            // Retrieve user
            var user = await _userManager.FindByIdAsync(User.Identity.Name);

            if (user == null)
            {
                return(BadRequest(new ErrorDto(ErrorDto.UserNotFound, "User not found")));
            }

            // Generate response containing the shared key and url for the authenticator app
            var response = new User2faSetupResponseDto();

            await LoadSharedKeyAndQrCodeUrlAsync(user, response);

            return(Ok(response));
        }