microsoft/healthcare-shared-components

Public

mirrored from https://github.com/microsoft/healthcare-shared-componentsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.0.0-1.0.79

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Microsoft.Health.Client/AuthenticationHttpMessageHandler.cs

35lines · modecode

1// -------------------------------------------------------------------------------------------------
2// Copyright (c) Microsoft Corporation. All rights reserved.
3// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
4// -------------------------------------------------------------------------------------------------
5
6using System.Net.Http;
7using System.Net.Http.Headers;
8using System.Threading;
9using System.Threading.Tasks;
10using EnsureThat;
11
12namespace Microsoft.Health.Client
13{
14 public class AuthenticationHttpMessageHandler : DelegatingHandler
15 {
16 private readonly ICredentialProvider _credentialProvider;
17
18 public AuthenticationHttpMessageHandler(ICredentialProvider credentialProvider)
19 {
20 EnsureArg.IsNotNull(credentialProvider, nameof(credentialProvider));
21
22 _credentialProvider = credentialProvider;
23 }
24
25 protected override async Task<HttpResponseMessage> SendAsync(
26 HttpRequestMessage request,
27 CancellationToken cancellationToken)
28 {
29 request.Headers.Authorization =
30 new AuthenticationHeaderValue("Bearer", await _credentialProvider.GetBearerToken(cancellationToken));
31
32 return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
33 }
34 }
35}
36