Update application parts implementation

This commit is contained in:
Javier Calvarro Nelson 2018-03-22 14:31:21 -07:00
parent de86071b2c
commit 9e61d6bd98
10 changed files with 66 additions and 180 deletions

View File

@ -8,6 +8,15 @@
"Exclusions": {
"DOC_MISSING": {
"lib/netstandard2.0/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll": "This library contains precompiled views."
},
"ASSEMBLY_DESCRIPTION": {
"lib/netstandard2.0/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll": "Enter justification"
},
"NEUTRAL_RESOURCES_LANGUAGE": {
"lib/netstandard2.0/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll": "Enter justification"
},
"SERVICING_ATTRIBUTE": {
"lib/netstandard2.0/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll": "Enter justification"
}
}
}

View File

@ -8,7 +8,7 @@
<MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>
<MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>
<MicrosoftAspNetCoreHttpsPolicyPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreHttpsPolicyPackageVersion>
<MicrosoftAspNetCoreMvcPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreMvcPackageVersion>
<MicrosoftAspNetCoreMvcPackageVersion>2.1.0-a-preview2-application-part-18617</MicrosoftAspNetCoreMvcPackageVersion>
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreServerKestrelPackageVersion>
<MicrosoftAspNetCoreStaticFilesPackageVersion>2.1.0-preview2-30406</MicrosoftAspNetCoreStaticFilesPackageVersion>

View File

@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Authentication
/// <see cref="AzureADB2COptions"/>.
/// </param>
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
public static AuthenticationBuilder AddAzureADB2CBearer(this AuthenticationBuilder builder, Action<AzureADB2COptions> configureOptions) =>
public static AuthenticationBuilder AddAzureADB2CBearer(this AuthenticationBuilder builder, Action<AzureADB2COptions> configureOptions) =>
builder.AddAzureADB2CBearer(
AzureADB2CDefaults.BearerAuthenticationScheme,
AzureADB2CDefaults.JwtBearerAuthenticationScheme,
@ -49,7 +49,8 @@ namespace Microsoft.AspNetCore.Authentication
this AuthenticationBuilder builder,
string scheme,
string jwtBearerScheme,
Action<AzureADB2COptions> configureOptions) {
Action<AzureADB2COptions> configureOptions)
{
builder.AddPolicyScheme(scheme, displayName: null, configureOptions: o =>
{
@ -190,27 +191,22 @@ namespace Microsoft.AspNetCore.Authentication
private static void AddAdditionalMvcApplicationParts(IServiceCollection services)
{
var thisAssembly = typeof(AzureADB2CAuthenticationBuilderExtensions).Assembly;
var additionalReferences = thisAssembly
.GetCustomAttributes<AssemblyMetadataAttribute>()
.Where(am => string.Equals(am.Key, "Microsoft.AspNetCore.Mvc.AdditionalReference"))
.Select(am => am.Value.Split(',')[0])
.ToArray();
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
var mvcBuilder = services
.AddMvc()
.AddRazorPagesOptions(o => o.AllowAreas = true)
.ConfigureApplicationPartManager(apm =>
{
foreach (var reference in additionalReferences)
foreach (var reference in relatedAssemblies)
{
var fileName = Path.GetFileName(reference);
var filePath = Path.Combine(Path.GetDirectoryName(thisAssembly.Location), fileName);
var additionalAssembly = LoadAssembly(filePath);
// This needs to change to additional assembly part.
var additionalPart = new AdditionalAssemblyPart(additionalAssembly);
if (!apm.ApplicationParts.Any(ap => HasSameName(ap.Name, additionalPart.Name)))
var factory = (AzureADB2CPartFactory)ApplicationPartFactory.GetApplicationPartFactory(reference);
foreach (var additionalPart in factory.CreateApplicationParts())
{
apm.ApplicationParts.Add(additionalPart);
if (!apm.ApplicationParts.Any(ap => HasSameName(ap.Name, additionalPart.Name)))
{
apm.ApplicationParts.Add(additionalPart);
}
}
}
@ -219,29 +215,5 @@ namespace Microsoft.AspNetCore.Authentication
bool HasSameName(string left, string right) => string.Equals(left, right, StringComparison.Ordinal);
}
private static Assembly LoadAssembly(string filePath)
{
Assembly viewsAssembly = null;
if (File.Exists(filePath))
{
try
{
viewsAssembly = Assembly.LoadFile(filePath);
}
catch (FileLoadException)
{
throw new InvalidOperationException("Unable to load the precompiled views assembly in " +
$"'{filePath}'.");
}
}
else
{
throw new InvalidOperationException("Could not find the precompiled views assembly for 'Microsoft.AspNetCore.Authentication.AzureADB2C.UI' at " +
$"'{filePath}'.");
}
return viewsAssembly;
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
namespace Microsoft.AspNetCore.Authentication.AzureADB2C.UI
{
/// <summary>
/// <see cref="ApplicationPartFactory"/> for Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll
/// </summary>
public abstract class AzureADB2CPartFactory : ApplicationPartFactory
{
/// <inheritdoc />
public override IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly, string context) =>
Array.Empty<ApplicationPart>();
/// <summary>
/// Creates the list of <see cref="ApplicationPart"/> for a given application.
/// </summary>
/// <returns>The <see cref="ApplicationPart"/> list.</returns>
public abstract IEnumerable<ApplicationPart> CreateApplicationParts();
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
namespace Microsoft.AspNetCore.Authentication.AzureADB2C.UI
{
internal class AzureAdB2CViewsPartFactory : AzureADB2CPartFactory
{
public override IEnumerable<ApplicationPart> CreateApplicationParts()
{
yield return new CompiledRazorAssemblyPart(this.GetType().Assembly);
}
}
}

View File

@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Razor">
<Import Project="$(MSBuildThisFileDirectory)Microsoft.AspNetCore.Authentication.AzureADB2C.UI.props" />
<PropertyGroup>
<Description>ASP.NET Core Azure Active Directory B2C Integration provides components for easily integrating Azure Active Directory B2C authentication within your ASP.NET Core application.</Description>
<PrecompiledDescription>Precompiled views assembly for the ASP.NET Core Azure Active Directory B2C Integration package.</PrecompiledDescription>
@ -11,6 +9,7 @@
<PrecompiledAssemblyTitle Condition=" '$(PrecompiledAssemblyTitle)' == '' ">$(RazorTargetName).dll</PrecompiledAssemblyTitle>
<PreserveCompilationContext>false</PreserveCompilationContext>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProvideApplicationPartFactoryAttributeTypeName>Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureAdB2CViewsPartFactory, Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views</ProvideApplicationPartFactoryAttributeTypeName>
</PropertyGroup>
<ItemGroup>
@ -21,26 +20,8 @@
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_parameter1>Microsoft.AspNetCore.Mvc.AdditionalReference</_parameter1>
<_parameter2>$(RazorTargetName).dll,false</_parameter2>
</AssemblyAttribute>
<RazorCompile Include="AzureAdB2CViewsPartFactory.cs" />
<Compile Remove="AzureAdB2CViewsPartFactory.cs" />
</ItemGroup>
<ItemGroup>
<Content Update="Areas\AzureADB2C\Pages\_ViewStart.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
</ItemGroup>
<Target Name="VerifyBuildOutputs" AfterTargets="Build">
<PropertyGroup>
<ExpectedOutputFile>$(OutputPath)$(RazorTargetName).dll</ExpectedOutputFile>
</PropertyGroup>
<Error Text="Unable to find precompiled view file $(ExpectedOutputFile)" Condition="!Exists('$(ExpectedOutputFile)')" />
</Target>
<Import Project="$(MSBuildThisFileDirectory)Microsoft.AspNetCore.Authentication.AzureADB2C.UI.targets" />
</Project>

View File

@ -1,24 +0,0 @@
<Project>
<PropertyGroup>
<GeneratePrecompiledAssemblyInfo Condition="'$(GeneratePrecompiledAssemblyInfo)' == ''">true</GeneratePrecompiledAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(GeneratePrecompiledAssemblyInfo)' == 'true'">
<GeneratePrecompiledAssemblyCompanyAttribute Condition="'$(GeneratePrecompiledAssemblyCompanyAttribute)' == ''">true</GeneratePrecompiledAssemblyCompanyAttribute>
<GeneratePrecompiledAssemblyConfigurationAttribute Condition="'$(GeneratePrecompiledAssemblyConfigurationAttribute)' == ''">true</GeneratePrecompiledAssemblyConfigurationAttribute>
<GeneratePrecompiledAssemblyCopyrightAttribute Condition="'$(GeneratePrecompiledAssemblyCopyrightAttribute)' == ''">true</GeneratePrecompiledAssemblyCopyrightAttribute>
<GeneratePrecompiledAssemblyDescriptionAttribute Condition="'$(GeneratePrecompiledAssemblyDescriptionAttribute)' == ''">true</GeneratePrecompiledAssemblyDescriptionAttribute>
<GeneratePrecompiledAssemblyFileVersionAttribute Condition="'$(GeneratePrecompiledAssemblyFileVersionAttribute)' == ''">true</GeneratePrecompiledAssemblyFileVersionAttribute>
<GeneratePrecompiledAssemblyInformationalVersionAttribute Condition="'$(GeneratePrecompiledAssemblyInformationalVersionAttribute)' == ''">true</GeneratePrecompiledAssemblyInformationalVersionAttribute>
<GeneratePrecompiledAssemblyProductAttribute Condition="'$(GeneratePrecompiledAssemblyProductAttribute)' == ''">true</GeneratePrecompiledAssemblyProductAttribute>
<GeneratePrecompiledAssemblyTitleAttribute Condition="'$(GeneratePrecompiledAssemblyTitleAttribute)' == ''">true</GeneratePrecompiledAssemblyTitleAttribute>
<GeneratePrecompiledAssemblyVersionAttribute Condition="'$(GeneratePrecompiledAssemblyVersionAttribute)' == ''">true</GeneratePrecompiledAssemblyVersionAttribute>
<GeneratePrecompiledNeutralResourcesLanguageAttribute Condition="'$(GeneratePrecompiledNeutralResourcesLanguageAttribute)' == ''">true</GeneratePrecompiledNeutralResourcesLanguageAttribute>
</PropertyGroup>
<ItemGroup>
<RazorCompile Include="$(GeneratedCommitHashAttributeFile)" />
<RazorCompile Include="$(GeneratedInternalAspNetCoreAttributeFile)" />
</ItemGroup>
</Project>

View File

@ -1,91 +0,0 @@
<Project>
<!--
Note that this must run before every invocation of CoreCompile to ensure that all compiler
runs see the generated assembly info. There is at least one scenario involving Xaml
where CoreCompile is invoked without other potential hooks such as Compile or CoreBuild,
etc., so we hook directly on to CoreCompile. Furthermore, we must run *after*
PrepareForBuild to ensure that the intermediate directory has been created.
-->
<Target Name="GeneratePrecompiledAssemblyInfo" BeforeTargets="RazorCoreCompile" DependsOnTargets="PrepareForRazorCompile;CoreGeneratePrecompiledAssemblyInfo" Condition="'$(GeneratePrecompiledAssemblyInfo)' == 'true'" />
<Target Name="GetPrecompiledAssemblyAttributes" DependsOnTargets="GetAssemblyVersion">
<ItemGroup>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyCompanyAttribute" Condition="'$(Company)' != '' and '$(GeneratePrecompiledAssemblyCompanyAttribute)' == 'true'">
<_Parameter1>$(Company)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyConfigurationAttribute" Condition="'$(Configuration)' != '' and '$(GeneratePrecompiledAssemblyConfigurationAttribute)' == 'true'">
<_Parameter1>$(Configuration)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyCopyrightAttribute" Condition="'$(Copyright)' != '' and '$(GeneratePrecompiledAssemblyCopyrightAttribute)' == 'true'">
<_Parameter1>$(Copyright)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyDescriptionAttribute" Condition="'$(PrecompiledDescription)' != '' and '$(GeneratePrecompiledAssemblyDescriptionAttribute)' == 'true'">
<_Parameter1>$(PrecompiledDescription)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyFileVersionAttribute" Condition="'$(FileVersion)' != '' and '$(GeneratePrecompiledAssemblyFileVersionAttribute)' == 'true'">
<_Parameter1>$(FileVersion)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyInformationalVersionAttribute" Condition="'$(InformationalVersion)' != '' and '$(GeneratePrecompiledAssemblyInformationalVersionAttribute)' == 'true'">
<_Parameter1>$(InformationalVersion)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyProductAttribute" Condition="'$(Product)' != '' and '$(GeneratePrecompiledAssemblyProductAttribute)' == 'true'">
<_Parameter1>$(Product)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyTitleAttribute" Condition="'$(PrecompiledAssemblyTitle)' != '' and '$(GeneratePrecompiledAssemblyTitleAttribute)' == 'true'">
<_Parameter1>$(PrecompiledAssemblyTitle)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyVersionAttribute" Condition="'$(AssemblyVersion)' != '' and '$(GeneratePrecompiledAssemblyVersionAttribute)' == 'true'">
<_Parameter1>$(AssemblyVersion)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Resources.NeutralResourcesLanguageAttribute" Condition="'$(NeutralLanguage)' != '' and '$(GeneratePrecompiledNeutralResourcesLanguageAttribute)' == 'true'">
<_Parameter1>$(NeutralLanguage)</_Parameter1>
</PrecompiledAssemblyAttribute>
<PrecompiledAssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(BuildNumber)' != ''">
<_Parameter1>BuildNumber</_Parameter1>
<_Parameter2>$(BuildNumber)</_Parameter2>
</PrecompiledAssemblyAttribute>
</ItemGroup>
</Target>
<!--
To allow version changes to be respected on incremental builds (e.g. through CLI parameters),
create a hash of all assembly attributes so that the cache file will change with the calculated
assembly attribute values and msbuild will then execute CoreGenerateAssembly to generate a new file.
-->
<Target Name="CreateGeneratedPrecompiledAssemblyInfoInputsCacheFile" BeforeTargets="RazorCompile" DependsOnTargets="GetPrecompiledAssemblyAttributes">
<PropertyGroup>
<GeneratedPrecompiledAssemblyInfoFile>$(IntermediateOutputPath)$(MSBuildProjectName).PrecompiledViews.AssemblyInfo$(DefaultLanguageSourceExtension)</GeneratedPrecompiledAssemblyInfoFile>
<GeneratedPrecompiledAssemblyInfoInputsCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).PrecompiledViews.AssemblyInfoInputs.cache</GeneratedPrecompiledAssemblyInfoInputsCacheFile>
</PropertyGroup>
<!-- We only use up to _Parameter1 for most attributes, but other targets may add additional assembly attributes with multiple parameters. -->
<Hash ItemsToHash="@(PrecompiledAssemblyAttribute->'%(Identity)%(_Parameter1)%(_Parameter2)%(_Parameter3)%(_Parameter4)%(_Parameter5)%(_Parameter6)%(_Parameter7)%(_Parameter8)')">
<Output TaskParameter="HashResult" PropertyName="_PrecompiledAssemblyAttributesHash" />
</Hash>
<WriteLinesToFile Lines="$(_PrecompiledAssemblyAttributesHash)" File="$(GeneratedPrecompiledAssemblyInfoInputsCacheFile)" Overwrite="True" WriteOnlyWhenDifferent="True" />
<ItemGroup>
<FileWrites Include="$(GeneratedPrecompiledAssemblyInfoInputsCacheFile)" />
</ItemGroup>
</Target>
<Target Name="CoreGeneratePrecompiledAssemblyInfo" DependsOnTargets="CreateGeneratedPrecompiledAssemblyInfoInputsCacheFile" Inputs="$(GeneratedPrecompiledAssemblyInfoInputsCacheFile)" Outputs="$(GeneratedPrecompiledAssemblyInfoFile)">
<PropertyGroup>
<GeneratedPrecompiledAssemblyInfoFile>$(IntermediateOutputPath)$(MSBuildProjectName).PrecompiledViews.AssemblyInfo$(DefaultLanguageSourceExtension)</GeneratedPrecompiledAssemblyInfoFile>
</PropertyGroup>
<ItemGroup>
<!-- Ensure the generated assemblyinfo file is not already part of the Compile sources, as a workaround for https://github.com/dotnet/sdk/issues/114 -->
<Compile Remove="$(GeneratedPrecompiledAssemblyInfoFile)" />
<Compile Remove="$(GeneratedAssemblyInfoFile)" />
</ItemGroup>
<ItemGroup>
<RazorCompile Include="$(GeneratedPrecompiledAssemblyInfoFile)" />
</ItemGroup>
<WriteCodeFragment AssemblyAttributes="@(PrecompiledAssemblyAttribute)" Language="$(Language)" OutputFile="$(GeneratedPrecompiledAssemblyInfoFile)">
<Output TaskParameter="OutputFile" ItemName="Compile" />
<Output TaskParameter="OutputFile" ItemName="FileWrites" />
</WriteCodeFragment>
</Target>
</Project>

View File

@ -3,4 +3,5 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]

View File

@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Authentication
// Assert
Assert.NotNull(provider.GetService<OpenIdConnectHandler>());
Assert.NotNull(provider.GetService<CookieAuthenticationHandler>());
Assert.NotNull(provider.GetService<VirtualAuthenticationHandler>());
Assert.NotNull(provider.GetService<PolicySchemeHandler>());
}
[Fact]
@ -171,7 +171,7 @@ namespace Microsoft.AspNetCore.Authentication
// Assert
Assert.NotNull(provider.GetService<JwtBearerHandler>());
Assert.NotNull(provider.GetService<VirtualAuthenticationHandler>());
Assert.NotNull(provider.GetService<PolicySchemeHandler>());
}
[Fact]