From 4cad7c80f9a0342fba46ecc9216a8fd80b1d5e56 Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Wed, 16 Feb 2022 13:11:55 -0800 Subject: [PATCH 1/3] Ensure `AccessToken` is not trimmed away Fixes: https://github.com/dotnet/aspnetcore/issues/32357
``` crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: An exception occurred executing JS interop: DeserializeNoConstructor, JsonConstructorAttribute, Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken Path: $.token | LineNumber: 0 | BytePositionInLine: 29.. See InnerException for more details. Microsoft.JSInterop.JSException: An exception occurred executing JS interop: DeserializeNoConstructor, JsonConstructorAttribute, Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken Path: $.token | LineNumber: 0 | BytePositionInLine: 29.. See InnerException for more details. ---> System.NotSupportedException: DeserializeNoConstructor, JsonConstructorAttribute, Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken Path: $.token | LineNumber: 0 | BytePositionInLine: 29. ---> System.NotSupportedException: DeserializeNoConstructor, JsonConstructorAttribute, Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken Exception_EndOfInnerExceptionStack at System.Text.Json.ThrowHelper.ThrowNotSupportedException(ReadStack& , Utf8JsonReader& , NotSupportedException ) at System.Text.Json.ThrowHelper.ThrowNotSupportedException_DeserializeNoConstructor(Type , Utf8JsonReader& , ReadStack& ) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnTryRead(Utf8JsonReader& , Type , JsonSerializerOptions , ReadStack& , AccessToken& ) at System.Text.Json.Serialization.JsonConverter`1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryRead(Utf8JsonReader& , Type , JsonSerializerOptions , ReadStack& , AccessToken& ) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.AccessToken, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadJsonAndSetMember(Object , ReadStack& , Utf8JsonReader& ) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnTryRead(Utf8JsonReader& , Type , JsonSerializerOptions , ReadStack& , InternalAccessTokenResult& ) at System.Text.Json.Serialization.JsonConverter`1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryRead(Utf8JsonReader& , Type , JsonSerializerOptions , ReadStack& , InternalAccessTokenResult& ) at System.Text.Json.Serialization.JsonConverter`1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCore(Utf8JsonReader& , JsonSerializerOptions , ReadStack& ) at System.Text.Json.Serialization.JsonConverter`1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCoreAsObject(Utf8JsonReader& , JsonSerializerOptions , ReadStack& ) at System.Text.Json.JsonSerializer.ReadCore[Object](JsonConverter , Utf8JsonReader& , JsonSerializerOptions , ReadStack& ) at System.Text.Json.JsonSerializer.Read[Object](Utf8JsonReader& , JsonTypeInfo ) at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& , Type , JsonSerializerOptions ) at Microsoft.JSInterop.JSRuntime.EndInvokeJS(Int64 , Boolean , Utf8JsonReader& ) Exception_EndOfInnerExceptionStack at Microsoft.JSInterop.JSRuntime.d__16`1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.InternalAccessTokenResult, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext() at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService`3.d__22[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteUserAccount, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.WebAssembly.Authentication.ApiAuthorizationProviderOptions, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext() at Microsoft.AspNetCore.Components.WebAssembly.Authentication.AuthorizationMessageHandler.SendAsync(HttpRequestMessage , CancellationToken ) at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage , CancellationToken ) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage , HttpCompletionOption , CancellationTokenSource , Boolean , CancellationTokenSource , CancellationToken ) at System.Net.Http.Json.HttpClientJsonExtensions.d__13`1[[BlazorApp1.Shared.WeatherForecast[], BlazorApp1.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at BlazorApp1.Client.Pages.FetchData.OnInitializedAsync() at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState ) u @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 kt @ blazor.webassembly.js:1 mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 _mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 $func194 @ 008c609a:0x17786 $func165 @ 008c609a:0x16d84 $func105 @ 008c609a:0x71fc $func104 @ 008c609a:0x60b7 $func7266 @ 008c609a:0x18187e $func1535 @ 008c609a:0x715af $func1539 @ 008c609a:0x71cda $mono_wasm_invoke_method @ 008c609a:0x1b3a1f Module._mono_wasm_invoke_method @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS @ _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS:23 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 kt @ blazor.webassembly.js:1 mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 _mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 $func194 @ 008c609a:0x17786 $func165 @ 008c609a:0x16d84 $func105 @ 008c609a:0x71fc $func104 @ 008c609a:0x60b7 $func7266 @ 008c609a:0x18187e $func1535 @ 008c609a:0x715af $func1539 @ 008c609a:0x71cda $mono_wasm_invoke_method @ 008c609a:0x1b3a1f Module._mono_wasm_invoke_method @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS @ _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS:23 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 kt @ blazor.webassembly.js:1 mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 _mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 $func194 @ 008c609a:0x17786 $func165 @ 008c609a:0x16d84 $func105 @ 008c609a:0x71fc $func104 @ 008c609a:0x60b7 $func7266 @ 008c609a:0x18187e $func1535 @ 008c609a:0x715af $func1533 @ 008c609a:0x71521 $func992 @ 008c609a:0x530ae $func194 @ 008c609a:0x1773f $func165 @ 008c609a:0x16d84 $func105 @ 008c609a:0x71fc $func104 @ 008c609a:0x60b7 $func7266 @ 008c609a:0x18187e $func1535 @ 008c609a:0x715af $func1539 @ 008c609a:0x71cda $mono_wasm_invoke_method @ 008c609a:0x1b3a1f Module._mono_wasm_invoke_method @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS @ _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS:23 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 kt @ blazor.webassembly.js:1 mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 _mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 $func194 @ 008c609a:0x17786 $func165 @ 008c609a:0x16d84 $func105 @ 008c609a:0x71fc $func104 @ 008c609a:0x60b7 $func7266 @ 008c609a:0x18187e $func1535 @ 008c609a:0x715af $func1539 @ 008c609a:0x71cda $mono_wasm_invoke_method @ 008c609a:0x1b3a1f Module._mono_wasm_invoke_method @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS @ _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS:23 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 kt @ blazor.webassembly.js:1 mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 _mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 $func194 @ 008c609a:0x17786 $func165 @ 008c609a:0x16d84 $func105 @ 008c609a:0x71fc $func104 @ 008c609a:0x60b7 $func7266 @ 008c609a:0x18187e $func1535 @ 008c609a:0x715af $func1539 @ 008c609a:0x71cda $mono_wasm_invoke_method @ 008c609a:0x1b3a1f Module._mono_wasm_invoke_method @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS @ _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS:23 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 kt @ blazor.webassembly.js:1 mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 _mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 $func194 @ 008c609a:0x17786 $func165 @ 008c609a:0x16d84 $func105 @ 008c609a:0x71fc $func104 @ 008c609a:0x60b7 $func7266 @ 008c609a:0x18187e $func1535 @ 008c609a:0x715af $func1539 @ 008c609a:0x71cda $mono_wasm_invoke_method @ 008c609a:0x1b3a1f Module._mono_wasm_invoke_method @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS @ _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_EndInvokeJS:23 endInvokeJSFromDotNet @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 Promise.then (async) beginInvokeJSFromDotNet @ blazor.webassembly.js:1 kt @ blazor.webassembly.js:1 mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 _mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 $func194 @ 008c609a:0x17786 $func165 @ 008c609a:0x16d84 $func105 @ 008c609a:0x71fc $func104 @ 008c609a:0x60b7 $func7266 @ 008c609a:0x18187e $func1535 @ 008c609a:0x715af $func1539 @ 008c609a:0x71cda $mono_wasm_invoke_method @ 008c609a:0x1b3a1f Module._mono_wasm_invoke_method @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 BINDINGS_SetTaskSourceResult @ BINDINGS_SetTaskSourceResult:24 o. @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 (anonymous) @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 Promise.then (async) _wrap_js_thenable_as_task @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 _js_to_mono_obj @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 js_to_mono_obj @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 (anonymous) @ blazor.webassembly.js:1 kt @ blazor.webassembly.js:1 mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 _mono_wasm_invoke_js_blazor @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 $func194 @ 008c609a:0x17786 $func165 @ 008c609a:0x16d84 $func105 @ 008c609a:0x71fc $func104 @ 008c609a:0x60b7 $func7266 @ 008c609a:0x18187e $func1535 @ 008c609a:0x715af $func1539 @ 008c609a:0x71cda $mono_wasm_invoke_method @ 008c609a:0x1b3a1f Module._mono_wasm_invoke_method @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:12 _call_method_with_converted_args @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 call_method @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 (anonymous) @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 mono_call_assembly_entry_point @ dotnet.7.0.0-preview.2.22103.2.n9t5r83lkh.js:3 callEntryPoint @ blazor.webassembly.js:1 Nt @ blazor.webassembly.js:1 await in Nt (async) (anonymous) @ blazor.webassembly.js:1 (anonymous) @ blazor.webassembly.js:1 ```
--- .../src/Services/RemoteAuthenticationService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs index 1b3f44b1c8c7..4ffe310768f0 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs @@ -165,6 +165,7 @@ public virtual async ValueTask RequestAccessToken() } /// + [DynamicDependency(JsonSerialized, typeof(AccessToken))] [DynamicDependency(JsonSerialized, typeof(AccessTokenRequestOptions))] public virtual async ValueTask RequestAccessToken(AccessTokenRequestOptions options) { From c5fb38cae44b2cae853720060917ca6cf54c086d Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Wed, 16 Feb 2022 13:43:48 -0800 Subject: [PATCH 2/3] Update RemoteAuthenticationService.cs --- .../src/Services/RemoteAuthenticationService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs index 4ffe310768f0..93b4733630ae 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs @@ -165,7 +165,6 @@ public virtual async ValueTask RequestAccessToken() } /// - [DynamicDependency(JsonSerialized, typeof(AccessToken))] [DynamicDependency(JsonSerialized, typeof(AccessTokenRequestOptions))] public virtual async ValueTask RequestAccessToken(AccessTokenRequestOptions options) { @@ -244,6 +243,7 @@ private void UpdateUser(Task task) } // Internal for testing purposes +[DynamicDependency(JsonSerialized, typeof(AccessToken))] internal struct InternalAccessTokenResult { public string Status { get; set; } From 827bd4de55c4722e6da777584f06d02567173bb9 Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Wed, 16 Feb 2022 13:53:20 -0800 Subject: [PATCH 3/3] Revert last --- .../src/Services/RemoteAuthenticationService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs index 93b4733630ae..4ffe310768f0 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs @@ -165,6 +165,7 @@ public virtual async ValueTask RequestAccessToken() } /// + [DynamicDependency(JsonSerialized, typeof(AccessToken))] [DynamicDependency(JsonSerialized, typeof(AccessTokenRequestOptions))] public virtual async ValueTask RequestAccessToken(AccessTokenRequestOptions options) { @@ -243,7 +244,6 @@ private void UpdateUser(Task task) } // Internal for testing purposes -[DynamicDependency(JsonSerialized, typeof(AccessToken))] internal struct InternalAccessTokenResult { public string Status { get; set; }