Skip to content

Commit

Permalink
Upgrade Marain.Tenancy.Client to Corvus.Identity v3 (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
idg10 authored Dec 1, 2021
1 parent dba927a commit c760f63
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 533 deletions.
8 changes: 5 additions & 3 deletions Solutions/Marain.Tenancy.Cli/Marain/Tenancy/Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace Marain.Tenancy.Cli
{
using System;
using System.Threading.Tasks;
using Corvus.Identity.ManagedServiceIdentity.ClientAuthentication;

using Corvus.Identity.ClientAuthentication.Azure;

using Marain.Tenancy.Client;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -35,12 +37,12 @@ public static async Task Main(string[] args)
services.AddJsonNetDateTimeOffsetToIso8601AndUnixTimeConverter();
services.AddSingleton<JsonConverter>(new StringEnumConverter(true));

var msiTokenSourceOptions = new AzureManagedIdentityTokenSourceOptions
var msiTokenSourceOptions = new LegacyAzureServiceTokenProviderOptions
{
AzureServicesAuthConnectionString = ctx.Configuration["AzureServicesAuthConnectionString"],
};

services.AddAzureManagedIdentityBasedTokenSource(msiTokenSourceOptions);
services.AddServiceIdentityAzureTokenCredentialSourceFromLegacyConnectionString(msiTokenSourceOptions);

var tenancyClientOptions = new TenancyClientOptions
{
Expand Down
8 changes: 8 additions & 0 deletions Solutions/Marain.Tenancy.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Cli: list": {
"commandName": "Project",
"commandLineArgs": "list"
}
}
}
2 changes: 1 addition & 1 deletion Solutions/Marain.Tenancy.Cli/appsettings.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// If running with a local tenancy service, point TenancyClient:TenancyServiceBaseUri at the localhost address for that
// and set the ResourceIdForMsiAuthentication to an empty string.
"TenancyClient:TenancyServiceBaseUri": "https://mardevtenancy.azurewebsites.net/",
"TenancyClient:ResourceIdForMsiAuthentication": "f1815180-9920-477b-95cc-7b93c2cd5de0"
"TenancyClient:ResourceIdForMsiAuthentication": "e7281b1b-6540-4c1b-ac18-eb0c2d42bfbf"

// If TenancyClient:TenancyServiceBaseUri refers to an instance in Azure, or if you've configured
// TenantCosmosContainerFactoryOptions, this local service will need to authenticate.
Expand Down
494 changes: 142 additions & 352 deletions Solutions/Marain.Tenancy.Cli/packages.lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageReference Include="CacheCow.Client" Version="2.8.3" />
<PackageReference Include="Corvus.ContentHandling.Json" Version="2.0.11" />
<PackageReference Include="Corvus.Extensions" Version="1.1.4" />
<PackageReference Include="Corvus.Identity.ManagedServiceIdentity.ClientAuthentication" Version="1.0.7" />
<PackageReference Include="Corvus.Identity.MicrosoftRest" Version="3.0.0-alpha.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="[3.1.*,)" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.23" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace Marain.Tenancy.Client
using System.Net.Http;
using CacheCow.Client;
using Corvus.Extensions.Json;
using Corvus.Identity.ManagedServiceIdentity.ClientAuthentication;
using Corvus.Identity.ClientAuthentication;
using Corvus.Identity.ClientAuthentication.MicrosoftRest;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Rest;
using Newtonsoft.Json;
Expand Down Expand Up @@ -44,10 +45,19 @@ public static IServiceCollection AddTenancyClient(
/// <param name="enableResponseCaching">Flag indicating whether or not response caching should be enabled for GET operations.</param>
/// <returns>The modified service collection.</returns>
/// <remarks>
/// <para>
/// This requires the <see cref="TenancyClientOptions"/> to be available from DI in order
/// to discover the base URI of the Operations control service, and, if required, to
/// specify the resource id to use when obtaining an authentication token representing the
/// hosting service's identity.
/// </para>
/// <para>
/// This also requires an implementation of <see cref="IServiceIdentityAccessTokenSource"/>
/// to be available via DI. This is normally achieved through one of the various
/// <c>AddServiceIdentityAzureTokenCredentialSource...</c> extension methods available when
/// you install the <c>Corvus.Identity.Azure</c> NuGet package, but applications are free
/// to supply alternate implementations.
/// </para>
/// </remarks>
public static IServiceCollection AddTenancyClient(
this IServiceCollection services,
Expand Down Expand Up @@ -75,9 +85,9 @@ public static IServiceCollection AddTenancyClient(
else
{
var tokenCredentials = new TokenCredentials(
new ServiceIdentityTokenProvider(
sp.GetRequiredService<IServiceIdentityTokenSource>(),
options.ResourceIdForMsiAuthentication));
new MicrosoftRestTokenProvider(
sp.GetRequiredService<IServiceIdentityAccessTokenSource>(),
$"{options.ResourceIdForMsiAuthentication}/.default"));
service = new TenancyService(options.TenancyServiceBaseUri, tokenCredentials, handlers);
}

Expand Down
8 changes: 4 additions & 4 deletions Solutions/Marain.Tenancy.Host.Functions/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@
},
"Corvus.Storage.Azure.BlobStorage.Tenancy": {
"type": "Transitive",
"resolved": "3.0.0-make-v2config-legacy-public.3",
"contentHash": "6m+s8Ki5m7xl0tXtjUdE/1SsFlkip5/rNh3REy3tQKg8oHUO4VHbj3CjjMFBrAtQQ/wb95aHiL1az3R8pJBceA==",
"resolved": "3.0.0-alpha.3",
"contentHash": "aQ/WtonoXdEtJbnx5H9++LyOQscxdsOLR7B6u4SIWYsNqq3Lsxb9GNmVN2OVh3TaaMPoLCKVUEUUKd2Sp/t/Rg==",
"dependencies": {
"Corvus.Storage.Azure.BlobStorage": "3.0.0-1-refactor-from-tenancy.10",
"Corvus.Tenancy.Abstractions": "3.0.0-make-v2config-legacy-public.3"
"Corvus.Tenancy.Abstractions": "3.0.0-alpha.3"
}
},
"Corvus.Storage.Common": {
Expand Down Expand Up @@ -1903,7 +1903,7 @@
"marain.tenancy.storage.azure.blobstorage": {
"type": "Project",
"dependencies": {
"Corvus.Storage.Azure.BlobStorage.Tenancy": "3.0.0-make-v2config-legacy-public.3",
"Corvus.Storage.Azure.BlobStorage.Tenancy": "3.0.0-alpha.3",
"Microsoft.Extensions.DependencyInjection.Abstractions": "3.1.0"
}
}
Expand Down
Loading

0 comments on commit c760f63

Please sign in to comment.