I'm trying to fetch MongoDB Atlas logs via a function app, but unable to get correct nonce value.
I've encountered a problem that I haven't been able to solve for a while now.
Purpose
----------
An azure function that downloads audit logs from MongoDB Atlas and stores it in an azure storage container.
Setup
----------
Mongo DB Atlas cluster and function are only accessible when connected to a VPN. MongoDB requires additional auth otherwise returns access denied. I'm using digest authentication. I've tested downloading the file via postman, and sending it to be stored in a storage container. Both work as expected.
Issue
----------
- My code makes a request which is rejected.
- The headers are parsed to extract the realm and nonce.
- Values are taken in by a helper method that generates a digest header.
- Digest header is added to DefaultRequestHeaders.
- 2nd request is made but auth fails. Nonce returned is different to nonce supplied (presumably because each request generates a unique value).
Question
----------
What am I doing incorrectly? My guess is that making the second request is somehow wrong and I need to return header during the 1st request - otherwise I don't understand how I get the nonce value from an api request before calling it (which is impossible afaik)
Code
----------
using System.Collections.Generic;
using System;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
namespace mongoDB_Atlas.logs.ExternalApiFunction
{
public class Class1
{
// Client.
private static readonly HttpClient client = new HttpClient();
//--------------------------------------------------------------------------------------//
// No Auth Function
//--------------------------------------------------------------------------------------//
[Function("no-auth")]
public static async Task