title: Use same authorization policies for client and server in Blazor
body: <p><em>This question is a follow-up from my <code>ASP.NET Core hosted Blazor</code> issue reported <a href="https://github.com/aspnet/AspNetCore/issues/12391" rel="nofollow noreferrer">here</a>.</em></p>
  
  <p>Using the current preview (6) for .NET Core 3.0, the <code>ASP.NET Core hosted Blazor</code> project template creates the following three projects:</p>
  
  <ul>
  <li>MyProject.Client (<strong>.NET Standard 2.0</strong>)</li>
  <li>MyProject.Server (<strong>.NET Core 3.0</strong>)</li>
  <li>MyProject.Shared (<strong>.NET Standard 2.0</strong>)</li>
  </ul>
  
  <p>I want to enable authorization in my server project (to protect the endpoints), as well as in my client project (to dynamically show or hide views or parts of views).</p>
  
  <p>For that use case I created the policies in the <code>MyProject.Shared</code> project, after which I could use them in the client project. However, they were not available in the server project.</p>
  
  <p><strong>The problems:</strong> </p>
  
  <ol>
  <li><ul>
  <li>.NET Core 3.0 authorization policies derive from <code>Microsoft.AspNetCore.Authorization.AuthorizationPolicy</code> defined by the <code>&lt;FrameworkReference Include="Microsoft.AspNetCore.App" /&gt;</code>.</li>
  <li>.NET Standard 2.0 authorization policies derive from <code>Microsoft.AspNetCore.Authorization.AuthorizationPolicy</code> defined by <code>&lt;PackageReference Include="Microsoft.AspNetCore.Authorization" [...] /&gt;</code>.</li>
  </ul></li>
  <li><ul>
  <li>The <code>AuthorizationPolicy</code> constructor requires a set of authentication schemes. </li>
  <li>For .NET Core 3.0 those are defined in <code>Microsoft.AspNetCore.Identity.IdentityConstants</code> defined by the <code>&lt;FrameworkReference Include="Microsoft.AspNetCore.App" /&gt;</code>.</li>
  <li>For .NET Standard 2.0 those are defined in <code>Microsoft.AspNetCore.Identity.IdentityConstants</code> defined by <code>&lt;PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" /&gt;</code>. However, this package won't be available in any higher version than <code>2.2.0</code>, as <a href="https://github.com/aspnet/AspNetCore/issues/3756" rel="nofollow noreferrer">Microsoft decided to discontinue certain packages</a> with the .NET Core 3.0 release, and rather move those classes into the <code>&lt;FrameworkReference Include="Microsoft.AspNetCore.App" /&gt;</code>.</li>
  </ul></li>
  </ol>
  
  <p><strong>My questions:</strong><br>
  What is the correct way to use the <strong>same</strong> policies - without defining them twice for .NET Standard and .NET Core - in both the server and client project?</p>
  
  <ul>
  <li>Take the compability between the framework reference of <code>Microsoft.AspNetCore.App</code> and the NuGet package <code>Microsoft.AspNetCore.Authorization (3.0.0)</code> for granted?</li>
  <li>Take the compability between the framework reference of <code>Microsoft.AspNetCore.App</code> and the NuGet package <code>Microsoft.AspNetCore.Identity (2.2.0)</code> for granted?</li>
  </ul>
  
  <hr>
  
  <p><strong>Edit:</strong> In order to correctly setup the shared policies in the <code>MyProject.Shared</code> project, I have to reference the <code>Microsoft.AspNetCore.Identity (2.2.0)</code> package - to include <code>IdentityConstants.ApplicationScheme</code>.
  However, this causes the build of <code>MyProject.Client</code> to fail:</p>
  
  <pre><code>2&gt;Processing embedded resource linker descriptor: mscorlib.xml
  2&gt;Duplicate preserve in resource mscorlib.xml in mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e of System.Threading.WasmRuntime (All).  Duplicate uses (All)
  2&gt;Type Mono.ValueTuple has no fields to preserve
  2&gt;Type System.Reflection.Assembly has no fields to preserve
  2&gt;Fatal error in IL Linker
  2&gt;
  2&gt;Unhandled Exception: Mono.Linker.MarkException: Error processing method: 'System.Void System.Security.Permissions.PrincipalPermission::Demand()' in assembly: 'System.Security.Permissions.dll' ---&gt; Mono.Cecil.ResolutionException: Failed to resolve System.Security.Principal.IPrincipal System.Threading.Thread::get_CurrentPrincipal()
  2&gt;   at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
  2&gt;   at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
  2&gt;   at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
  2&gt;   at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
  2&gt;   at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
  2&gt;   at Mono.Linker.Steps.MarkStep.ProcessQueue()
  2&gt;   --- End of inner exception stack trace ---
  2&gt;   at Mono.Linker.Steps.MarkStep.ProcessQueue()
  2&gt;   at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
  2&gt;   at Mono.Linker.Steps.MarkStep.Process()
  2&gt;   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
  2&gt;   at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
  2&gt;   at Mono.Linker.Pipeline.Process(LinkContext context)
  2&gt;   at Mono.Linker.Driver.Run(ILogger customLogger)
  2&gt;   at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
  2&gt;   at Mono.Linker.Driver.Main(String[] args)
  </code></pre>
  
  <p>Followed up by this cryptic error message:</p>
  
  <pre><code>\.nuget\packages\microsoft.aspnetcore.blazor.build\3.0.0-preview6.19307.2\targets\Blazor.MonoRuntime.targets(439,5): error MSB3073: The command "dotnet "C:\Users\Stefan\.nuget\packages\microsoft.aspnetcore.blazor.mono\0.10.0-preview6.19303.4\build\netstandard1.0\../../tools/illink/illink.dll" -l none --disable-opt unreachablebodies --verbose --strip-security true --exclude-feature com --exclude-feature sre -v false -c link -u link -b true -d "C:\Users\Stefan\.nuget\packages\microsoft.aspnetcore.blazor.mono\0.10.0-preview6.19303.4\build\netstandard1.0\../../tools/mono/bcl/" -d "C:\Users\Stefan\.nuget\packages\microsoft.aspnetcore.blazor.mono\0.10.0-preview6.19303.4\build\netstandard1.0\../../tools/mono/bcl/Facades/" -o "S:\git\hou-units\src\UNITS\UNITS.Client\obj\Debug\netstandard2.0\blazor\linker/" -x "C:\Users\Stefan\.nuget\packages\microsoft.aspnetcore.blazor.build\3.0.0-preview6.19307.2\targets\BuiltInBclLinkerDescriptor.xml" -x "S:\git\hou-units\src\UNITS\UNITS.Client\obj\Debug\netstandard2.0\blazor\linker.descriptor.xml" -a "C:\Users\Stefan\.nuget\packages\jetbrains.annotations\2019.1.3\lib\netstandard2.0\JetBrains.Annotations.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.authentication\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.authentication.abstractions\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.Abstractions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.authentication.cookies\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.Cookies.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.authentication.core\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.Core.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.aspnetcore.authorization\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.Authorization.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.aspnetcore.blazor\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.Blazor.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.aspnetcore.components\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.Components.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.aspnetcore.components.browser\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.Components.Browser.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.cryptography.internal\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Cryptography.Internal.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.cryptography.keyderivation\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Cryptography.KeyDerivation.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.dataprotection\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.DataProtection.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.dataprotection.abstractions\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.DataProtection.Abstractions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.hosting.abstractions\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.hosting.server.abstractions\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Server.Abstractions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http.abstractions\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http.extensions\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Extensions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http.features\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.identity\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Identity.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.aspnetcore.metadata\3.0.0-preview6.19307.2\lib\netstandard2.0\Microsoft.AspNetCore.Metadata.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.webutilities\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.WebUtilities.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.extensions.configuration\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.extensions.configuration.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.extensions.configuration.binder\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.extensions.dependencyinjection\3.0.0-preview6.19304.6\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\3.0.0-preview6.19304.6\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.fileproviders.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Abstractions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.hosting.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Hosting.Abstractions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.identity.core\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Identity.Core.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.extensions.logging\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.extensions.logging.abstractions\3.0.0-preview6.19304.6\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.objectpool\2.2.0\lib\netstandard2.0\Microsoft.Extensions.ObjectPool.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.extensions.options\3.0.0-preview6.19304.6\lib\netstandard2.0\Microsoft.Extensions.Options.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.extensions.primitives\3.0.0-preview6.19304.6\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.webencoders\2.2.0\lib\netstandard2.0\Microsoft.Extensions.WebEncoders.dll" -a "C:\Users\Stefan\.nuget\packages\microsoft.jsinterop\3.0.0-preview6.19304.6\lib\netstandard2.0\Microsoft.JSInterop.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.net.http.headers\2.2.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.win32.registry\4.5.0\lib\netstandard2.0\Microsoft.Win32.Registry.dll" -a "C:\Users\Stefan\.nuget\packages\mono.webassembly.interop\3.0.0-preview6.19304.6\lib\netstandard2.0\Mono.WebAssembly.Interop.dll" -a "C:\Users\Stefan\.nuget\packages\newtonsoft.json\12.0.2\lib\netstandard2.0\Newtonsoft.Json.dll" -a "C:\Users\Stefan\.nuget\packages\system.buffers\4.5.0\lib\netstandard2.0\System.Buffers.dll" -a "C:\Users\Stefan\.nuget\packages\system.componentmodel.annotations\4.6.0-preview6.19303.8\lib\netstandard2.0\System.ComponentModel.Annotations.dll" -a "C:\Users\Stefan\.nuget\packages\system.memory\4.5.3\lib\netstandard2.0\System.Memory.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.numerics.vectors\4.5.0\lib\netstandard2.0\System.Numerics.Vectors.dll" -a "C:\Users\Stefan\.nuget\packages\system.runtime.compilerservices.unsafe\4.6.0-preview6.19303.8\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.security.accesscontrol\4.5.0\lib\netstandard2.0\System.Security.AccessControl.dll" -a "C:\Users\Stefan\.nuget\packages\system.security.cryptography.cng\4.4.0\lib\netstandard2.0\System.Security.Cryptography.Cng.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.security.cryptography.pkcs\4.5.0\lib\netstandard2.0\System.Security.Cryptography.Pkcs.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.security.cryptography.xml\4.5.0\lib\netstandard2.0\System.Security.Cryptography.Xml.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.security.permissions\4.5.0\lib\netstandard2.0\System.Security.Permissions.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.security.principal.windows\4.5.0\lib\netstandard2.0\System.Security.Principal.Windows.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.text.encodings.web\4.5.0\lib\netstandard2.0\System.Text.Encodings.Web.dll" -a "C:\Users\Stefan\.nuget\packages\system.text.json\4.6.0-preview6.19303.8\lib\netstandard2.0\System.Text.Json.dll" -a "C:\Users\Stefan\.nuget\packages\system.threading.tasks.extensions\4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll" -a "S:\git\hou-units\src\UNITS\UNITS.Shared\bin\Debug\netstandard2.0\UNITS.Shared.dll" -a "S:\git\hou-units\src\UNITS\UNITS.Client\obj\Debug\netstandard2.0\UNITS.Client.dll"" exited with code -532462766.
  </code></pre>
  
  <p><strong>Example project can be found <a href="https://github.com/Herdo/hou-units/tree/prototype-blazor/src/UNITS" rel="nofollow noreferrer">on GitHub</a>.</strong></p>