Description
This issue has been moved from a ticket on Developer Community.
I have created a Blazor application and I use Msal to do authentication following the examples from Azure B2C.
With my B2C configuration in the server, I can successfully login, I get the User, the claims and I can call the api.
I would need to have access to the token during development to be able to use that token to call my api services directly using swagger. So during Debugging I wanted to print the token on screen to copy and paste.
However, when I try to get the token in the Client after successful login, I get an Exception:
An exception occurred executing JS interop: The JSON value could not be converted to System.DateTimeOffset. Path: $.token.expires
This is a very confusing exception and doesn't seem to explain the type of error that is occurring. It seems that is not doing any validation during the parsing or pre-parsing. So not sure why this is happening.
More details:
I initialise with this:
builder. Services.AddMsalAuthentication(options =>
{
builder. Configuration.Bind("AzureAdB2C", options. ProviderOptions.Authentication);
//options. ProviderOptions.DefaultAccessTokenScopes.Add("02200220-20202-2020-2020-202020200202002"); // I tried to put the application Id a per documentation and it doesn't work
options. ProviderOptions.DefaultAccessTokenScopes.Add("openid");
options. ProviderOptions.DefaultAccessTokenScopes.Add("offline_access");
// request scope to access the API
options. ProviderOptions.AdditionalScopesToConsent.Add("https://myb2c.onmicrosoft.com/whateverApp/MyAPI");
options. ProviderOptions.LoginMode = "redirect";
});
I also use a custom AuthorizationMessageHandler to be able to call the api, which works well.
However, when in my code I call the code to retrieve the Token, I get the exception + one unhandled exception:
[Inject]
public IAccessTokenProvider TokenProvider { get; set; }
...
var accessTokenResult = await TokenProvider.RequestAccessToken(); // <-- This throws exception
And additionally there is an unhandled exception:
Unhandled Exception:
System.Text.Json.JsonException: Invalid JSON
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.EndInvokeJS(JSRuntime jsRuntime, String arguments)
at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.<>c.<EndInvokeJS> b__7_0(String argsJson)
at Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyCallQueue.Schedule[String](String state, Action`1 callback)
at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.EndInvokeJS(String argsJson)
Uncaught Error: System.Text.Json.JsonException: Invalid JSONThe thread 0x1b444 has exited with code 0 (0x0).
I have tried in B2C to set the configuration, and I'm able to run the SignIn flow redirecting to jwt.ms passing the token and decoding it.
And I get the token decoded when redirecting directly to jwt.ms:
Original Comments
Feedback Bot on 11/12/2021, 00:15 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)
Activity
mkArtakMSFT commentedon Jan 10, 2022
Thanks for contacting us. This is already fixed as part of #38962 / #39060.
TanayParikh commentedon Jan 10, 2022
Please note, the fix for this issue should be available in the 6.0.2 patch release.
rmencia-isv commentedon Jan 17, 2022
Any estimates on this?
I've got this installed 6.0.200-preview.21617.4 and still not working
TanayParikh commentedon Jan 18, 2022
The fix for the underlying
System.Text.Json.JsonException: Invalid JSON
exception was backported through #39075.@rmencia-isv could you please try this out using the latest installer available at https://github.com/dotnet/installer. Please let us know if you're still having the issue with that, and please provide the exact version of the dotnet sdk being used, along side the exact exception message you're getting.
rmencia-isv commentedon Jan 19, 2022
I have installed the latest versionfrom the url you provided (dotnet-sdk-6.0.200-preview.22068.4-win-x64.exe) and I still get the same error in Blazor wasm client app.
Checking the list I have this one installed (6.0.200-preview.22068.4)
However, by looking at the call stack I see references to Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=6.0.1.0*
The error Message:
An exception occurred executing JS interop: The JSON value could not be converted to System.DateTimeOffset. Path: $.token.expires | LineNumber: 0 | BytePositionInLine: 73.. See InnerException for more details.
InnerException:
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
at System.Text.Json.Serialization.JsonConverter
1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.Serialization.JsonConverter
1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)at System.Text.Json.JsonSerializer.ReadCore[Object](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.Read[Object](Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
at Microsoft.JSInterop.JSRuntime.EndInvokeJS(Int64 taskId, Boolean succeeded, Utf8JsonReader& jsonReader)'
TanayParikh commentedon Jan 19, 2022
Ah that's definitely a bit strange. Could you please double check your csproj files to ensure you don't have any hardcoded versions which may be causing this issue? Also, if you could try adding the following to your nuget config:
Further details here.
rmencia-isv commentedon Jan 19, 2022
This is what I have in the project file.
I also added the nuget in VS to get the packages from that place and no new updates available, even pre-release for any of those packages.
TanayParikh commentedon Jan 19, 2022
Hey @rmencia-isv, I took a look at the feeds and you're right the 6.0.2 (prerelease) packages aren't up yet. You can either try waiting for the official 6.0.2 release (mid February), or try the 7.0 alpha packages (not sure if they'll be updated yet though).
rmencia-isv commentedon Jan 19, 2022
Thanks Tanay for getting back to me. It's unfortunate that the packages are not uploaded yet, as I've seen a number of issues fixed.
I'll probably wait for the release next month, if the pre release packages are not updated.
53 remaining items
asieradzk commentedon Jul 27, 2022
Guys fix this?
ekuhlmann23 commentedon Aug 27, 2022
@kbeaugrand Could you provide more details on the workaround, please?
kbeaugrand commentedon Aug 27, 2022
@ekuhlmann23,
I simply moved the settings to specify the authentication response type to ``code```.
e.g:
Magik3a commentedon Sep 1, 2022
So, using new Blazor project with default B2C configuration is still erroring on the profile page.


So lets wait as the other guys on this :@
javiercn commentedon Sep 15, 2022
We have made improvements to this scenario in .NET 7.0, the changes will be available in RC2.
It should be easier to diagnostic when there is an issue in the configuration of the app.
#43954