| | | 1 | | namespace Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction |
| | | 2 | | { |
| | | 3 | | using System; |
| | | 4 | | using System.Net.Http; |
| | | 5 | | using System.Threading; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | using Microsoft.Rest; |
| | | 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 predictionKey; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Creates a new instance of the ApiKeyServiceClientCredentails class |
| | | 18 | | /// </summary> |
| | | 19 | | /// <param name="predictionKey">The prediction key to authenticate and authorize as</param> |
| | 16 | 20 | | public ApiKeyServiceClientCredentials(string predictionKey) |
| | | 21 | | { |
| | 16 | 22 | | this.predictionKey = predictionKey; |
| | 16 | 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 | | { |
| | 16 | 32 | | if (request == null) |
| | 0 | 33 | | throw new ArgumentNullException("request"); |
| | | 34 | | |
| | 16 | 35 | | request.Headers.Add("Prediction-Key", this.predictionKey); |
| | | 36 | | |
| | 16 | 37 | | return Task.FromResult<object>(null); |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | } |