| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using Azure.Core.Pipeline; |
| | 5 | |
|
| | 6 | | namespace Azure.Core |
| | 7 | | { |
| | 8 | | internal class AzureKeyCredentialPolicy : HttpPipelineSynchronousPolicy |
| | 9 | | { |
| | 10 | | private readonly string _name; |
| | 11 | | private readonly AzureKeyCredential _credential; |
| | 12 | |
|
| | 13 | | /// <summary> |
| | 14 | | /// Initializes a new instance of the <see cref="AzureKeyCredentialPolicy"/> class. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="credential">The <see cref="AzureKeyCredential"/> used to authenticate requests.</param> |
| | 17 | | /// <param name="name">The name of the key header used for the credential.</param> |
| 516 | 18 | | public AzureKeyCredentialPolicy(AzureKeyCredential credential, string name) |
| | 19 | | { |
| 516 | 20 | | Argument.AssertNotNull(credential, nameof(credential)); |
| 516 | 21 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| 516 | 22 | | _credential = credential; |
| 516 | 23 | | _name = name; |
| 516 | 24 | | } |
| | 25 | |
|
| | 26 | | /// <inheritdoc/> |
| | 27 | | public override void OnSendingRequest(HttpMessage message) |
| | 28 | | { |
| 2852 | 29 | | base.OnSendingRequest(message); |
| 2852 | 30 | | message.Request.Headers.SetValue(_name, _credential.Key); |
| 2852 | 31 | | } |
| | 32 | | } |
| | 33 | | } |