When doing HTTP requests I specify the OAuth2 token in my code in the following way:
WebClient webClient = ...;
webClient.Headers.Add("Authorization", $"Bearer {accessToken}");
But when uri
is redirect one, then following request failured, because Authorization
header is stipped on redirect:
HttpWebRequest request = (HttpWebRequest)webClient.GetWebRequest(uri); // public method in derived class
It is possible to disable AllowAutoRedirect
and set it to false
, and then manually handle redirects.
Is it a simpler way to handle redirects avoiding manual handling, and preserve access token?