| | 1 | | using System; |
| | 2 | | using System.Net.Http; |
| | 3 | | using System.Threading; |
| | 4 | | using System.Threading.Tasks; |
| | 5 | | using Microsoft.Rest; |
| | 6 | |
|
| | 7 | | namespace Microsoft.Azure.CognitiveServices.Personalizer |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Allows authentication to the API using a basic apiKey mechanism |
| | 11 | | /// </summary> |
| | 12 | | public class ApiKeyServiceClientCredentials : ServiceClientCredentials |
| | 13 | | { |
| | 14 | | private readonly string subscriptionKey; |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Creates a new instance of the ApiKeyServiceClientCredentials class |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="subscriptionKey">The subscription key to authenticate and authorize as</param> |
| 34 | 20 | | public ApiKeyServiceClientCredentials(string subscriptionKey) |
| | 21 | | { |
| 34 | 22 | | this.subscriptionKey = subscriptionKey; |
| 34 | 23 | | } |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Add the Basic Authentication Header to each outgoing request |
| | 27 | | /// </summary> |
| | 28 | | /// <param name="request">The outgoing request</param> |
| | 29 | | /// <param name="cancellationToken">A token to cancel the operation</param> |
| | 30 | | public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) |
| | 31 | | { |
| 34 | 32 | | if (request == null) |
| | 33 | | { |
| 0 | 34 | | throw new ArgumentNullException("request"); |
| | 35 | | } |
| | 36 | |
|
| 34 | 37 | | request.Headers.Add("Ocp-Apim-Subscription-Key", this.subscriptionKey); |
| 34 | 38 | | return Task.FromResult<object>(null); |
| | 39 | | } |
| | 40 | | } |
| | 41 | | } |
| | 42 | |
|