| | | 1 | | using System.Net.Http; |
| | | 2 | | using System.Threading; |
| | | 3 | | using System.Threading.Tasks; |
| | | 4 | | using Microsoft.Rest; |
| | | 5 | | |
| | | 6 | | namespace ApplicationCore.Analytics |
| | | 7 | | { |
| | | 8 | | public class CredentialsFactory : ICredentialsFactory |
| | | 9 | | { |
| | | 10 | | public ServiceClientCredentials CreateApiKeyServiceCredentials(string subscriptionKey) |
| | 1 | 11 | | { |
| | 1 | 12 | | return new ApiKeyServiceClientCredentials(subscriptionKey); |
| | 1 | 13 | | } |
| | | 14 | | |
| | | 15 | | private class ApiKeyServiceClientCredentials : ServiceClientCredentials |
| | | 16 | | { |
| | | 17 | | private readonly string _subscriptionKey; |
| | | 18 | | |
| | 1 | 19 | | public ApiKeyServiceClientCredentials(string subscriptionKey) |
| | 1 | 20 | | { |
| | 1 | 21 | | _subscriptionKey = subscriptionKey; |
| | 1 | 22 | | } |
| | | 23 | | |
| | | 24 | | public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken ct) |
| | 1 | 25 | | { |
| | 1 | 26 | | request.Headers.Add("Ocp-Apim-Subscription-Key", _subscriptionKey); |
| | 1 | 27 | | return base.ProcessHttpRequestAsync(request, ct); |
| | 1 | 28 | | } |
| | | 29 | | } |
| | | 30 | | } |
| | | 31 | | } |