Can one use a .NET service worker (.NET 6) to access an API controller secured via default authentication in an asp.NET core MVC project

I am assigned a task on my job to make a script that calls an API endpoint every hour or so. the API is supposed to check failed payments to see if they have succeeded.

namespace MVCProject.Areas.Admin 
// this is not the real code it is a recreated dummy one meant to represent the code. I don't have //access to the original code, I only created this to recreate the API to be called in the real //code!
{
    [Area("Admin")]
    [Authorize]
    public class PaymentController : Controller
    {
        [HttpGet]
        public async Task<ActionResult<MessageCode>> Check()
        {
            int status = CustomRandomNumberGenerator.GenerateRandomNumber();

            string description = status == 1 ? "Payment Settled!" : "Payment Unsettled!"; 

            MessageCode message = new MessageCode()
            {
                Time = DateTime.Now,
                State = status,
                Description = description
            };

            return Ok(message);
        }
    }
}

I proposed to use a .NET service worker. with the following ExecuteAsync() Services and all injected.

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
    while (!stoppingToken.IsCancellationRequested)
    {
        await LoginAndGetCookieAsync(); // getting over here is the problem
       
        var response = await _httpClient.GetAsync(_requestURL);


        var responseJson = await response.Content.ReadAsStringAsync();
        var responseObject = JsonSerializer.Deserialize<MessageCode>(responseJson);

        if (responseObject != null)
        {
            _logger.LogInformation(@"Payment check: {0}", responseObject.ToString());
        }
        else
        {
            _logger.LogInformation("Payment service is down!");
        }

        await Task.Delay(5000, stoppingToken); // Wait for 5 seconds
    }
}

the trouble is the aforementioned API is within an asp.NET core MVC project with the individual accounts authentication option picked when the API was created(Identity Razor pages was later scaffolded to gain access to the pages) It obviously was not programmed with automation in mind! I’m unable to change the original check API. I only have access to (https://APIdomain.com/Identity/Account/Login) which is not really meant to be called by a worker. my boss is insistent not to change the outsourced API to a token based scheme or to include the worker in the Original API calling the internal service directly to make it self-running skipping this whole mess, for the fear of it crashing. I was asked to do a demo project so the can mimic however I succeed in doing this.

Here is what I have tries so far with the LoginAndGetCookieAsync():

private async Task LoginAndGetTokensAsync()
{
    // first i tried to pass user and password in the form of JSON got 400(BadRequest)
     Input input = new Input()
     {
        Email = _email,
        Password = _password
     };


     var jsonInput = JsonSerializer.Serialize(input);

     var loginResponse = await _httpClient.PostAsync(_loginURL, new StringContent(jsonInput, Encoding.UTF8, "application/json"));
    //then GPT 3.5 told me to try this resulted a 400 again! like due to my poor understanding
    //of how the API is really ment to be called
    var content = new FormUrlEncodedContent(new Dictionary<string, string>
    {
        { "Input.Email", "[email protected]" },
        { "Input.Password", "P@rs6!" },
        { "Input.RememberMe", "false" }
    });
    var loginResponse = await _httpClient.PostAsync(_loginURL, content);

    if (loginResponse.StatusCode == HttpStatusCode.Found)
    {
        var loginJson = await loginResponse.Content.ReadAsStringAsync();

        try
        {
            var loginResult = JsonSerializer.Deserialize<CookieResponse>(loginJson);
            var cookie = loginResult?._RequestVerificationToken ?? "";
            _logger.LogInformation(cookie);
        }
        catch (JsonException ex)
        {
            _logger.LogError(ex, "Error deserializing JSON response in  LoginAndGetTokensAsync");
        }
    }
    else
    {
        _logger.LogError("Failed to login. Status code: {0}", loginResponse.StatusCode);
    }
}

how do I decipher the Login endpoint to make it return a cookie enabling me to use it in my _httpclient using This question ? should I? (even a hint would be appreciated.) Or should I convince my boss to change the original API and risk crashing it because it was not written with automation in mind.
if anybody wants to take a look at my demo code they are available at : WorkerProject and MVCProject

7

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật