| | 1 | | using Microsoft.Rest; |
| | 2 | | using System; |
| | 3 | | using System.Net.Http; |
| | 4 | | using System.Threading; |
| | 5 | | using System.Threading.Tasks; |
| | 6 | |
|
| | 7 | | namespace Microsoft.Azure.ApplicationInsights.Query |
| | 8 | | { |
| | 9 | | public class ApiKeyClientCredentials : ServiceClientCredentials |
| | 10 | | { |
| | 11 | | private string token; |
| | 12 | |
|
| 20 | 13 | | public ApiKeyClientCredentials(string token) |
| | 14 | | { |
| 20 | 15 | | if (string.IsNullOrEmpty(token)) |
| | 16 | | { |
| 0 | 17 | | throw new ArgumentException($"{nameof(token)} must not be null or empty"); |
| | 18 | | } |
| | 19 | |
|
| 20 | 20 | | this.token = token; |
| 20 | 21 | | } |
| | 22 | |
|
| | 23 | | public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) |
| | 24 | | { |
| 40 | 25 | | request.Headers.Add("x-api-key", token); |
| 40 | 26 | | return Task.FromResult(true); |
| | 27 | | } |
| | 28 | | } |
| | 29 | | } |