Skip to content

Commit

Permalink
Add missing client credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
tmarkovski committed Jul 29, 2019
1 parent 049f0e6 commit cf65711
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 1 addition & 2 deletions csharp/ServiceCollectionExtensions.cs
@@ -1,5 +1,4 @@
using System;
using Microsoft.Rest;
using System;
using Streetcred.ServiceClients;

namespace Microsoft.Extensions.DependencyInjection
Expand Down
2 changes: 1 addition & 1 deletion csharp/Streetcred.ServiceClients.csproj
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.20" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.20" />
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions csharp/StreetcredClientCredentials.cs
@@ -0,0 +1,37 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Microsoft.Rest;
// ReSharper disable CheckNamespace

namespace Microsoft.Extensions.DependencyInjection
{
internal class StreetcredClientCredentials : ServiceClientCredentials
{
/// <summary>
/// Gets the options.
/// </summary>
/// <value>
/// The options.
/// </value>
public ServiceClientOptions Options { get; }

/// <summary>
/// Initializes a new instance of the <see cref="StreetcredClientCredentials"/> class.
/// </summary>
/// <param name="options">The options.</param>
public StreetcredClientCredentials(IOptions<ServiceClientOptions> options)
{
Options = options.Value;
}

/// <inheritdoc />
public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.Headers.Add("Authorization", $"Bearer {Options.AccessToken}");
request.Headers.Add("X-Streetcred-Subscription-Key", Options.SubscriptionKey);
return base.ProcessHttpRequestAsync(request, cancellationToken);
}
}
}

0 comments on commit cf65711

Please sign in to comment.