0

Struggling with MAUI to send a GET call from Android device to an API that requires Bearer auth. Setting the Authorization header in the HttpClient like so:

client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token);

However at the API endpoint, the Authorization header is not being received at all.

We have also tried sending an HttpRequestMessage with the Authorization header set explicitly, but still no dice.

James McCormack
  • 9,217
  • 3
  • 47
  • 57

1 Answers1

1

It turned out the API we were sending to was running on both HTTP and HTTPS URLs.

In our android client config, we were sending to the HTTP URL.

Then we noticed that our API was set to redirect HTTP->HTTPS : app.UseHttpsRedirection();

So it turns out that Auth headers are stripped on redirect!

Authorization header is lost on redirect

When we changed our Android config to call the HTTPS URL directly, the Auth header started being received correctly.

James McCormack
  • 9,217
  • 3
  • 47
  • 57