| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. See License.txt in the project root for license information. |
| | | 3 | | |
| | | 4 | | using Microsoft.Rest; |
| | | 5 | | using System; |
| | | 6 | | using System.Net.Http; |
| | | 7 | | using System.Threading; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | |
| | | 10 | | namespace Microsoft.Azure.Attestation |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// The Attestation credential class that implements <see cref="ServiceClientCredentials"/> |
| | | 14 | | /// </summary> |
| | | 15 | | public class AttestationCredentials : ServiceClientCredentials |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Bearer token |
| | | 19 | | /// </summary> |
| | 28 | 20 | | public string Token { get; set; } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Constructor. |
| | | 24 | | /// </summary> |
| | | 25 | | /// <param name="token"> token. </param> |
| | 8 | 26 | | public AttestationCredentials(string token) |
| | | 27 | | { |
| | 8 | 28 | | if (string.IsNullOrEmpty(token)) |
| | | 29 | | { |
| | 0 | 30 | | throw new ArgumentException($"{nameof(token)} must not be null or empty"); |
| | | 31 | | } |
| | | 32 | | |
| | 8 | 33 | | this.Token = token; |
| | 8 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// ProcessHttpRequestAsync. |
| | | 38 | | /// </summary> |
| | | 39 | | /// <param name="request"> request. </param> |
| | | 40 | | /// <param name="cancellationToken"> cancellationToken. </param> |
| | | 41 | | public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) |
| | | 42 | | { |
| | 20 | 43 | | if (request == null) |
| | | 44 | | { |
| | 0 | 45 | | throw new ArgumentNullException(nameof(request)); |
| | | 46 | | } |
| | | 47 | | |
| | 20 | 48 | | request.Headers.Add("Authorization", $"Bearer {Token}"); |
| | 20 | 49 | | return Task.FromResult(true); |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |