I added the System.IdentityModel.Tokens.Jwt package to my Blazor-project to handle JWT on the client. When building, I got the usual error about not being able to link because of dependencies, such as "Semaphore".
3>TestApp.Client -> S:\Downloads\TestApp\src\TestApp.Client\bin\Debug\netstandard2.0\TestApp.Client.dll
3>Cannot find declaration of exported type 'System.Threading.Semaphore' from the assembly 'System.Threading, Version=4.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
3>Fatal error in IL Linker
3>Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Private.DataContractSerialization, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
3> at Mono.Linker.DirectoryAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
3> at Mono.Linker.AssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
3> at Mono.Linker.DirectoryAssemblyResolver.Resolve(AssemblyNameReference name)
3> at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
3> at Mono.Linker.Steps.ResolveFromAssemblyStep.ProcessLibrary(LinkContext context, AssemblyDefinition assembly, RootVisibility rootVisibility)
3> at Mono.Linker.Steps.ResolveFromAssemblyStep.ProcessLibrary(AssemblyDefinition assembly)
3> at Mono.Linker.Steps.ResolveFromAssemblyStep.Process()
3> at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
3> at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
3> at Mono.Linker.Pipeline.Process(LinkContext context)
3> at Mono.Linker.Driver.Run(ILogger customLogger)
3> at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
Is there a way to get around this? What is preventing me from using the package?
Try disabling the linker by adding the following MSBuild property: <BlazorLinkOnBuild>false</BlazorLinkOnBuild>
Now I get this in the browser:
Blazor is running in dev mode without IL stripping. To make the bundle size significantly smaller, publish the application or see https://go.microsoft.com/fwlink/?linkid=870414
blazor.webassembly.js:1 Debugging hotkey: Shift+Alt+D (when application has focus)
blazor.webassembly.js:1 WASM: Initialized
blazor.webassembly.js:1 WASM: False
blazor.webassembly.js:1 WASM: CANNOT HANDLE COOKIE DDI
blazor.webassembly.js:1 WASM: * Assertion at /mnt/jenkins/workspace/test-mono-mainline-wasm/label/ubuntu-1804-amd64/mono/mini/wasm_m2n_invoke.g.h:547, condition `0' not met
blazor.webassembly.js:1 WASM:
localhost/:1 Uncaught (in promise) abort(). Build with -s ASSERTIONS=1 for more info.
How do I debug this?
@robertsundstrom I know that it is not an answer to your question, but why do you want to use System.IdentityModel.Tokens.Jwt on the client side? Here https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/ we can read:
Includes types that provide support for creating, serializing and validating JSON Web Tokens.
I have no experience with JWT yet, but if I understand correctly types defined in System.IdentityModel.Tokens.Jwt are more useful on the server. Am I missing something? Are you going to create a Blazor application which displays information encoded in JWT or you need JWT for authentication?
@Andrzej-W My intent is to use the parser to create a ClaimsPrincipal in my attempt to build a client-side authentication system. Previously, I just parsed the token with another package (JWT). I want a standardized interface for receiving the claims - and thought ClaimsPrincipal was the right way cause it would mirror server-side.
The experimental code (in its current state) can be found here: https://github.com/robertsundstrom/blazor-sample-app
I'm unable to compile your project:
NSwag bin directory: C:\Users\aw\.nuget\packages\nswag.msbuild\11.20.1\tools\NetCore21
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Extensions.Configuration.IConfiguration' while attempting to activate 'TestApp.Server.Startup'.
OK. I get that error only when the NSwag task is running. I wonder why. It used to work in the previous commit (with the linker enabled).
Looks like this is hitting me too, I just imported the same assembly in order to do a better job of pulling the information out from a JWT token, issued to my client for authentication.
Adding that lib, now gives me:
>blazor.jwttest.Client -> I:\Programming Projects\Blazor\blazor.jwttest\blazor.jwttest.Client\bin\Debug\netstandard2.0\blazor.jwttest.Client.dll
2>Cannot find declaration of exported type 'System.Threading.Semaphore' from the assembly 'System.Threading, Version=4.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
2>Fatal error in IL Linker
2>Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Private.DataContractSerialization, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
2> at Mono.Linker.DirectoryAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
2> at Mono.Linker.AssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
2> at Mono.Linker.DirectoryAssemblyResolver.Resolve(AssemblyNameReference name)
2> at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
2> at Mono.Linker.Steps.ResolveFromAssemblyStep.ProcessLibrary(LinkContext context, AssemblyDefinition assembly, RootVisibility rootVisibility)
2> at Mono.Linker.Steps.ResolveFromAssemblyStep.ProcessLibrary(AssemblyDefinition assembly)
2> at Mono.Linker.Steps.ResolveFromAssemblyStep.Process()
2> at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
2> at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
2> at Mono.Linker.Pipeline.Process(LinkContext context)
2> at Mono.Linker.Driver.Run(ILogger customLogger)
2> at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
2>C:\Users\shawty\.nuget\packages\microsoft.aspnetcore.blazor.build\0.6.0\targets\Blazor.MonoRuntime.targets(446,5): error MSB3073: The command "dotnet "C:\Users\shawty\.nuget\packages\microsoft.aspnetcore.blazor.build\0.6.0\targets\../tools/illink/illink.dll" -l none --verbose --strip-security true --exclude-feature com --exclude-feature sre -v false -c link -u link -b true -d "C:\Users\shawty\.nuget\packages\microsoft.aspnetcore.blazor.build\0.6.0\targets\../tools/mono/bcl/" -d "C:\Users\shawty\.nuget\packages\microsoft.aspnetcore.blazor.build\0.6.0\targets\../tools/mono/bcl/Facades/" -o "I:\Programming Projects\Blazor\blazor.jwttest\blazor.jwttest.Client\obj\Debug\netstandard2.0\blazor\linker/" -x "I:\Programming Projects\Blazor\blazor.jwttest\blazor.jwttest.Client\Linker.xml" -a "C:\Users\shawty\.nuget\packages\blazor.extensions.storage\0.1.6\lib\netstandard2.0\Blazor.Extensions.Storage.JS.dll" -a "C:\Users\shawty\.nuget\packages\blazor.extensions.storage\0.1.6\lib\netstandard2.0\Blazor.Extensions.Storage.dll" -a "C:\Users\shawty\.nuget\packages\microsoft.aspnetcore.blazor\0.6.0\lib\netstandard2.0\Microsoft.AspNetCore.Blazor.dll" -a "C:\Users\shawty\.nuget\packages\microsoft.aspnetcore.blazor.browser\0.6.0\lib\netstandard2.0\Microsoft.AspNetCore.Blazor.Browser.dll" -a "C:\Users\shawty\.nuget\packages\microsoft.aspnetcore.blazor.build\0.6.0\lib\netstandard1.0\Microsoft.AspNetCore.Blazor.TagHelperWorkaround.dll" -a "C:\Users\shawty\.nuget\packages\microsoft.extensions.dependencyinjection\2.1.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.dll" -a "C:\Users\shawty\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\2.1.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll" -a "C:\Users\shawty\.nuget\packages\microsoft.identitymodel.logging\5.3.0\lib\netstandard2.0\Microsoft.IdentityModel.Logging.dll" -a "C:\Users\shawty\.nuget\packages\microsoft.identitymodel.tokens\5.3.0\lib\netstandard2.0\Microsoft.IdentityModel.Tokens.dll" -a "C:\Users\shawty\.nuget\packages\microsoft.jsinterop\0.6.0\lib\netstandard2.0\Microsoft.JSInterop.dll" -a "C:\Users\shawty\.nuget\packages\mono.webassembly.interop\0.6.0\lib\netstandard2.0\Mono.WebAssembly.Interop.dll" -a "C:\Users\shawty\.nuget\packages\newtonsoft.json\11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll" -a "C:\Users\shawty\.nuget\packages\system.collections.concurrent\4.3.0\lib\netstandard1.3\System.Collections.Concurrent.dll" -a "C:\Users\shawty\.nuget\packages\system.io.filesystem.primitives\4.3.0\lib\netstandard1.3\System.IO.FileSystem.Primitives.dll" -a "C:\Users\shawty\.nuget\packages\system.linq\4.3.0\lib\netstandard1.6\System.Linq.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.private.datacontractserialization\4.3.0\lib\netstandard1.3\System.Private.DataContractSerialization.dll" -a "C:\Users\shawty\.nuget\packages\system.reflection.emit\4.3.0\lib\netstandard1.3\System.Reflection.Emit.dll" -a "C:\Users\shawty\.nuget\packages\system.reflection.emit.ilgeneration\4.3.0\lib\netstandard1.3\System.Reflection.Emit.ILGeneration.dll" -a "C:\Users\shawty\.nuget\packages\system.reflection.emit.lightweight\4.3.0\lib\netstandard1.3\System.Reflection.Emit.Lightweight.dll" -a "C:\Users\shawty\.nuget\packages\system.reflection.typeextensions\4.3.0\lib\netstandard1.5\System.Reflection.TypeExtensions.dll" -a "C:\Users\shawty\.nuget\packages\system.runtime.interopservices.runtimeinformation\4.3.0\lib\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll" -a "C:\Users\shawty\.nuget\packages\system.runtime.numerics\4.3.0\lib\netstandard1.3\System.Runtime.Numerics.dll" -a "C:\Users\shawty\.nuget\packages\system.runtime.serialization.primitives\4.3.0\lib\netstandard1.3\System.Runtime.Serialization.Primitives.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.runtime.serialization.xml\4.3.0\lib\netstandard1.3\System.Runtime.Serialization.Xml.dll" -a "C:\Users\shawty\.nuget\packages\system.security.claims\4.3.0\lib\netstandard1.3\System.Security.Claims.dll" -a "C:\Users\shawty\.nuget\packages\system.security.cryptography.openssl\4.3.0\lib\netstandard1.6\System.Security.Cryptography.OpenSsl.dll" -a "C:\Users\shawty\.nuget\packages\system.security.cryptography.primitives\4.3.0\lib\netstandard1.3\System.Security.Cryptography.Primitives.dll" -a "C:\Users\shawty\.nuget\packages\system.security.principal\4.3.0\lib\netstandard1.0\System.Security.Principal.dll" -a "C:\Users\shawty\.nuget\packages\system.text.regularexpressions\4.3.0\lib\netstandard1.6\System.Text.RegularExpressions.dll" -a "C:\Users\shawty\.nuget\packages\system.threading\4.3.0\lib\netstandard1.3\System.Threading.dll" -a "C:\Users\shawty\.nuget\packages\system.threading.tasks.extensions\4.3.0\lib\netstandard1.0\System.Threading.Tasks.Extensions.dll" -a "C:\Users\shawty\.nuget\packages\system.xml.readerwriter\4.3.0\lib\netstandard1.3\System.Xml.ReaderWriter.dll" -a "C:\Users\shawty\.nuget\packages\system.xml.xdocument\4.3.0\lib\netstandard1.3\System.Xml.XDocument.dll" -a "C:\Users\shawty\.nuget\packages\system.xml.xmldocument\4.3.0\lib\netstandard1.3\System.Xml.XmlDocument.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.xml.xmlserializer\4.3.0\lib\netstandard1.3\System.Xml.XmlSerializer.dll" -a "I:\Programming Projects\Blazor\blazor.jwttest\blazor.jwttest.Shared\bin\Debug\netstandard2.0\blazor.jwttest.Shared.dll" -a "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.identitymodel.tokens.jwt\5.2.0\lib\netstandard1.4\System.IdentityModel.Tokens.Jwt.dll" -a "I:\Programming Projects\Blazor\blazor.jwttest\blazor.jwttest.Client\obj\Debug\netstandard2.0\blazor.jwttest.Client.dll"" exited with code 1.
2>Done building project "blazor.jwttest.Client.csproj" -- FAILED.
@Andrzej-W we need to use this library on the client side in order to parse things like roles, and claims properties out of the token generated as part of the authentication in the backend. Issuing the token is one thing, but it's no use if we can't do things like look at the roles issued to a claimant, to compare them to page accesses etc.
I'd also like to add to my previous note that, many of the NuGet packages that are created for decoding and parsing JWT's use this library under the hood, I initially tried a bunch of them and hit various problems, so I rolled my own decoder, then I decided to try the Raw MS JWT libs, and alas, have hit problems again...
I just want the portion that decodes the token and produces a ClaimsIdentity, without the need to validate the token signature. I wanted to use ClaimsIdentity because this is a standard way of handling identities (building a service using that type of object).
When this library did not work, I decided to port that part by copying a lot of code from the repo. I really don't want to do that.
Looks like this was a Linker issue. If you still face this problem, please file an issue on the https://github.com/mono/mono repo.
Most helpful comment
I'd also like to add to my previous note that, many of the NuGet packages that are created for decoding and parsing JWT's use this library under the hood, I initially tried a bunch of them and hit various problems, so I rolled my own decoder, then I decided to try the Raw MS JWT libs, and alas, have hit problems again...