| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using System.Net.Http; |
| | 5 | | using System.Text; |
| | 6 | | using System.Threading; |
| | 7 | | using System.Threading.Tasks; |
| | 8 | |
|
| | 9 | | namespace Microsoft.Azure.KeyVault.Customized.Authentication |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// A <see cref="DelegatingHandler"/> which will update the <see cref="HttpBearerChallengeCache"/> when a 401 respon |
| | 13 | | /// </summary> |
| | 14 | | public class ChallengeCacheHandler : MessageProcessingHandler |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Returns the specified request without performing any processing |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="request"></param> |
| | 20 | | /// <param name="cancellationToken"></param> |
| | 21 | | /// <returns></returns> |
| | 22 | | protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationT |
| | 23 | | { |
| 922 | 24 | | return request; |
| | 25 | | } |
| | 26 | | /// <summary> |
| | 27 | | /// Updates the <see cref="HttpBearerChallengeCache"/> when the specified response has a return code of 401 |
| | 28 | | /// </summary> |
| | 29 | | /// <param name="response">The response to evaluate</param> |
| | 30 | | /// <param name="cancellationToken">The cancellation token</param> |
| | 31 | | /// <returns></returns> |
| | 32 | | protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, CancellationToken cancellat |
| | 33 | | { |
| | 34 | | // if the response came back as 401 and the response contains a bearer challenge update the challenge cache |
| 922 | 35 | | if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) |
| | 36 | | { |
| 8 | 37 | | HttpBearerChallenge challenge = HttpBearerChallenge.GetBearerChallengeFromResponse(response); |
| | 38 | |
|
| 8 | 39 | | if (challenge != null) |
| | 40 | | { |
| | 41 | | // Update challenge cache |
| 4 | 42 | | HttpBearerChallengeCache.GetInstance().SetChallengeForURL(response.RequestMessage.RequestUri, challe |
| | 43 | | } |
| | 44 | | } |
| | 45 | |
|
| 922 | 46 | | return response; |
| | 47 | | } |
| | 48 | |
|
| | 49 | | } |
| | 50 | | } |